Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/paramin-beta/netinterface.cc
[mareframe] / trunk / paramin-beta / netinterface.cc Repository:
ViewVC logotype

Annotation of /trunk/paramin-beta/netinterface.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (view) (download)

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 : agomez 6 //initialX.resize(1,xValue[numVarInDataGroup]);
108 :     //lowerScale.resize(1, lowerBound[numVarInDataGroup]);
109 :     //upperScale.resize(1, upperBound[numVarInDataGroup]);
110 :     initialX.resize(1,xValue[i]);
111 :     lowerScale.resize(1, lowerBound[i]);
112 :     upperScale.resize(1, upperBound[i]);
113 : agomez 1 numVarInDataGroup++;
114 :     };
115 :     dataConvert = new DataConverter();
116 :     dataConvert->setInitialData(optValue, xValue);
117 :     }
118 :     // have set opt info if any
119 :     //}
120 :     if (toscale == 1) {
121 :     scaler = new DataScaler();
122 :     scaler->setInitialData(lowerScale, upperScale);
123 :     lowerScale.Reset();
124 :     upperScale.Reset();
125 :     lowerScale.resize(numVarInDataGroup, -1.0);
126 :     upperScale.resize(numVarInDataGroup, 1.0);
127 :     // maybe need to do diff!!!
128 :     initialX = scaler->scaleX(initialX);
129 :     };
130 :    
131 :    
132 :     }
133 :    
134 :     // ********************************************************
135 :     // Function for initiating values before start using class NetInterface
136 :     // ********************************************************
137 :     void NetInterface::initiateNetComm(ProcessManager* pm) {
138 :     int netStarted, numProc;
139 :     isAlpha = -1;
140 :     pManager = pm;
141 :     net->setNumInSendVar(numVarToSend);
142 :     netStarted = startNetComm();
143 :     if (netStarted != 1) {
144 :     cerr << "Error in netinterface - could not start netcommunication\n";
145 :     exit(EXIT_FAILURE);
146 :     } else {
147 :     numProc = net->getNumProcesses();
148 :     if (numProc <=0) {
149 :     cerr << "Error in netinterface - no processes\n";
150 :     exit(EXIT_FAILURE);
151 :     }
152 :     pManager->initializePM(numProc);
153 :     numberOfTags = 0;
154 :     receiveID = -1;
155 :     }
156 :    
157 :     if (switches.Size() > 0)
158 :     sendStringValue();
159 :     if (lowerBound.Size() > 0)
160 :     sendBoundValues();
161 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge