1 : |
agomez |
1 |
#include "netinterface.h" |
2 : |
|
|
|
3 : |
|
|
// ********************************************************
|
4 : |
|
|
// Constructors and destructor for class NetInterface
|
5 : |
|
|
// ********************************************************
|
6 : |
|
|
NetInterface::NetInterface(NetCommunication* netComm,
|
7 : |
|
|
ProcessManager* pm, CommandLineInfo* commandline) {
|
8 : |
|
|
|
9 : |
|
|
maxNumX = 500;
|
10 : |
|
|
numTries = 4;
|
11 : |
|
|
scaler = NULL;
|
12 : |
|
|
dataConvert = NULL;
|
13 : |
|
|
dctrl = NULL;
|
14 : |
|
|
dataSet = NULL;
|
15 : |
|
|
numVarInDataGroup = 0;
|
16 : |
|
|
numVarToSend = 0;
|
17 : |
|
|
toscale = commandline->getScale();
|
18 : |
|
|
net = netComm;
|
19 : |
|
|
readInputFile(commandline->getInputFilename());
|
20 : |
|
|
|
21 : |
|
|
initiateNetComm(pm);
|
22 : |
|
|
}
|
23 : |
|
|
|
24 : |
|
|
NetInterface::~NetInterface() {
|
25 : |
|
|
int i;
|
26 : |
|
|
stopNetComm();
|
27 : |
|
|
stopUsingDataGroup();
|
28 : |
|
|
if (toscale == 1) {
|
29 : |
|
|
delete scaler;
|
30 : |
|
|
scaler = NULL;
|
31 : |
|
|
}
|
32 : |
|
|
if (dataConvert != NULL) {
|
33 : |
|
|
delete dataConvert;
|
34 : |
|
|
dataConvert = NULL;
|
35 : |
|
|
}
|
36 : |
|
|
/*
|
37 : |
|
|
if (switches.Size() > 0) {
|
38 : |
|
|
for (i = 0; i < switches.Size(); i++)
|
39 : |
|
|
delete [] switches[i];
|
40 : |
|
|
}
|
41 : |
|
|
*/
|
42 : |
|
|
}
|
43 : |
|
|
|
44 : |
|
|
// ********************************************************
|
45 : |
|
|
// Functions for reading input values from file
|
46 : |
|
|
// ********************************************************
|
47 : |
|
|
void NetInterface::readInputFile(char* initvalsFileName) {
|
48 : |
|
|
// must be careful about setX. that added to datagroup!!!
|
49 : |
|
|
// if needed....
|
50 : |
|
|
InitialInputFile* readInput = new InitialInputFile(initvalsFileName);
|
51 : |
|
|
readInput->readFromFile();
|
52 : |
|
|
|
53 : |
|
|
if (readInput->isRepeatedValues()) {
|
54 : |
|
|
this->setRepeatedValues(readInput);
|
55 : |
|
|
|
56 : |
|
|
} else {
|
57 : |
|
|
this->setOptInfo(readInput);
|
58 : |
|
|
};
|
59 : |
|
|
// need to check if better do diff or just keep this here and for sure
|
60 : |
|
|
// use numVarInDataGroup
|
61 : |
|
|
alphaX_h.resize(numVarInDataGroup, 0.0);
|
62 : |
|
|
delete readInput;
|
63 : |
|
|
}
|
64 : |
|
|
|
65 : |
|
|
void NetInterface::setRepeatedValues(InitialInputFile* data) {
|
66 : |
|
|
// initvalsFile contains only vector values, no optimization info
|
67 : |
|
|
DoubleVector xValue;
|
68 : |
|
|
data->getSwitches(switches);
|
69 : |
|
|
data->getValues(xValue);
|
70 : |
|
|
numVarToSend = xValue.Size();
|
71 : |
|
|
if (numVarToSend <= 0) {
|
72 : |
|
|
cerr << "Error in netinterface - could not read vectors from file\n";
|
73 : |
|
|
exit(EXIT_FAILURE);
|
74 : |
|
|
}
|
75 : |
|
|
numVarInDataGroup = numVarToSend;
|
76 : |
|
|
startNewDataGroup();
|
77 : |
|
|
setX(xValue);
|
78 : |
|
|
while (data->isDataLeft()) {
|
79 : |
|
|
data->readNextLine();
|
80 : |
|
|
data->getValues(xValue);
|
81 : |
|
|
setX(xValue);
|
82 : |
|
|
}
|
83 : |
|
|
}
|
84 : |
|
|
void NetInterface::setOptInfo(InitialInputFile* data) {
|
85 : |
|
|
int i;
|
86 : |
|
|
DoubleVector xValue;
|
87 : |
|
|
IntVector optValue;
|
88 : |
|
|
data->getVectors(switches, xValue, lowerBound, upperBound, optValue);
|
89 : |
|
|
numVarToSend = xValue.Size();
|
90 : |
|
|
if (numVarToSend <= 0) {
|
91 : |
|
|
cerr << "Error in netinterface - could not read vectors from file\n";
|
92 : |
|
|
exit(EXIT_FAILURE);
|
93 : |
|
|
}
|
94 : |
|
|
//cout << optValue[0] << "\n";
|
95 : |
|
|
//if (optValue.Size() == 0 || numVarToSend == optValue.Size()) {
|
96 : |
|
|
//// no opt info or all parameters used for optimizing
|
97 : |
|
|
//initialX = xValue;
|
98 : |
|
|
//lowerScale = lowerBound;
|
99 : |
|
|
//upperScale = upperBound;
|
100 : |
|
|
//numVarInDataGroup = numVarToSend;
|
101 : |
|
|
//}
|
102 : |
|
|
//else {
|
103 : |
|
|
numVarInDataGroup = 0;
|
104 : |
|
|
for (i = 0; i < numVarToSend; i++) {
|
105 : |
|
|
// cout << optValue[i] << "\n";
|
106 : |
|
|
if (optValue[i] == 1) {
|
107 : |
|
|
initialX.resize(1,xValue[numVarInDataGroup]);
|
108 : |
|
|
lowerScale.resize(1, lowerBound[numVarInDataGroup]);
|
109 : |
|
|
upperScale.resize(1, upperBound[numVarInDataGroup]);
|
110 : |
|
|
numVarInDataGroup++;
|
111 : |
|
|
};
|
112 : |
|
|
dataConvert = new DataConverter();
|
113 : |
|
|
dataConvert->setInitialData(optValue, xValue);
|
114 : |
|
|
}
|
115 : |
|
|
// have set opt info if any
|
116 : |
|
|
//}
|
117 : |
|
|
if (toscale == 1) {
|
118 : |
|
|
scaler = new DataScaler();
|
119 : |
|
|
scaler->setInitialData(lowerScale, upperScale);
|
120 : |
|
|
lowerScale.Reset();
|
121 : |
|
|
upperScale.Reset();
|
122 : |
|
|
lowerScale.resize(numVarInDataGroup, -1.0);
|
123 : |
|
|
upperScale.resize(numVarInDataGroup, 1.0);
|
124 : |
|
|
// maybe need to do diff!!!
|
125 : |
|
|
initialX = scaler->scaleX(initialX);
|
126 : |
|
|
};
|
127 : |
|
|
|
128 : |
|
|
|
129 : |
|
|
}
|
130 : |
|
|
|
131 : |
|
|
// ********************************************************
|
132 : |
|
|
// Function for initiating values before start using class NetInterface
|
133 : |
|
|
// ********************************************************
|
134 : |
|
|
void NetInterface::initiateNetComm(ProcessManager* pm) {
|
135 : |
|
|
int netStarted, numProc;
|
136 : |
|
|
isAlpha = -1;
|
137 : |
|
|
pManager = pm;
|
138 : |
|
|
net->setNumInSendVar(numVarToSend);
|
139 : |
|
|
netStarted = startNetComm();
|
140 : |
|
|
if (netStarted != 1) {
|
141 : |
|
|
cerr << "Error in netinterface - could not start netcommunication\n";
|
142 : |
|
|
exit(EXIT_FAILURE);
|
143 : |
|
|
} else {
|
144 : |
|
|
numProc = net->getNumProcesses();
|
145 : |
|
|
if (numProc <=0) {
|
146 : |
|
|
cerr << "Error in netinterface - no processes\n";
|
147 : |
|
|
exit(EXIT_FAILURE);
|
148 : |
|
|
}
|
149 : |
|
|
pManager->initializePM(numProc);
|
150 : |
|
|
numberOfTags = 0;
|
151 : |
|
|
receiveID = -1;
|
152 : |
|
|
}
|
153 : |
|
|
|
154 : |
|
|
if (switches.Size() > 0)
|
155 : |
|
|
sendStringValue();
|
156 : |
|
|
if (lowerBound.Size() > 0)
|
157 : |
|
|
sendBoundValues();
|
158 : |
|
|
}
|