/home/coin/SVN-release/OS-2.4.1/OS/src/OSAgent/OSSolverAgent.cpp

Go to the documentation of this file.
00001 /* $Id: OSSolverAgent.cpp 4292 2011-09-21 05:47:18Z kmartin $ */
00016 #include "OSSolverAgent.h"
00017 #include "OSWSUtil.h"
00018 #include "CoinTime.hpp"
00019 #include "OSParameters.h"
00020 
00021 #include <cstdlib>
00022 
00023 #ifdef HAVE_CTIME
00024 # include <ctime>
00025 #else
00026 # ifdef HAVE_TIME_H
00027 #  include <time.h>
00028 # else
00029 #  error "don't have header file for time"
00030 # endif
00031 #endif
00032 
00033 //#define DEBUG
00034 
00035 using std::string;
00036 using std::cout;
00037 using std::endl;
00038 
00039 OSSolverAgent::OSSolverAgent(string solverURI) : OShL()
00040 {
00041     int nstart = 0;
00042     string::size_type posSlash;
00043     // parse the solverURI
00044     // get rid of http:// if it is there
00045     if (solverURI.find("http://") != string::npos) solverURI = solverURI.substr(7);
00046     // now find the first "/" and put in nstart
00047     posSlash = solverURI.find("/", nstart);
00048     if(posSlash != std::string::npos) nstart = posSlash;
00049     postURI = solverURI.substr(nstart, solverURI.size() - 1);
00050     // Do we have a port number
00051     string::size_type colonlocation = solverURI.find(":");
00052     if(colonlocation == string::npos)
00053     {
00054         solverAddress = solverURI.substr(0, nstart);
00055         solverPortNumber = 80;
00056     }
00057     else
00058     {
00059         solverPortNumber = atoi( &solverURI.substr(colonlocation + 1, nstart - colonlocation - 1)[0] ) ;
00060         solverAddress = solverURI.substr(0, colonlocation);
00061     }
00062 }
00063 
00064 OSSolverAgent::~OSSolverAgent()
00065 {
00066 }
00067 
00068 string OSSolverAgent::solve(string osil, string osol)
00069 {
00070     string sOSrL ;
00071     string theSOAP;
00072     string solveResult;
00073     bool useCDATA = true;
00074     // CreateSOAPMessage inputs
00075     int numInputs = 2;
00076     string smethod = "solve";
00077     string msInputs[2];
00078     // package up the inputs
00079     // first run them through SAOPify, e.g. replace < with &lt; etc.
00080     msInputs[0] = WSUtil::SOAPify( osil, useCDATA) ;
00081     msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00082     string msInputNames[2] = {"osil", "osol"};
00083     string sSoapAction = "OSSolverService#solve";
00084     // create the soap
00085     double cpuTime =0;
00086     double startTime = 0;
00087     startTime = CoinCpuTime();
00088     theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00089                                         smethod, msInputs, msInputNames, sSoapAction);
00090     // send the soap to the HTTP server
00091     //std::cout << "SEND THE SOAP " << std::endl;
00092     cpuTime = CoinCpuTime() - startTime;
00093     //std::cout << "Soapify Cpu Time = "  << cpuTime <<  std::endl;
00094     startTime = CoinWallclockTime();
00095     solveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00096     cpuTime = CoinWallclockTime() - startTime;
00097     //std::cout << "Send Cpu Time = "  << cpuTime <<  std::endl;
00098     // desoapify the result -- i.e. replace &lt; with <  etc.
00099     //std::cout << "CALL DESOAP WITH THE FOLLOWING " << std::endl;
00100     //std::cout << solveResult << std::endl;
00101     solveResult = WSUtil::getOSxL(solveResult, "solve");
00102     //std::cout << "RETURN THE OSRL " << std::endl;
00103     //std::cout << solveResult << std::endl;
00104     useCDATA = false;
00105     sOSrL = WSUtil::deSOAPify( solveResult, useCDATA);
00106     //std::cout << "RETURN THE OSRL " << std::endl;
00107     //std::cout << sOSrL << std::endl;
00108     // strip out the OSxL that we want from the SOAP envelope
00109     //std::cout << "DONE WITH DESOAP " << std::endl;
00110     //std::cout << solveResult << std::endl;
00111     return sOSrL;
00112 }//end solve
00113 
00114 string OSSolverAgent::fileUpload( string osilFileName, string theOSiLFile)
00115 {
00116     string theHTTPPOST="";
00117     string uploadResult="";
00118     string boundaryName = "AaB03x";
00119     theHTTPPOST = WSUtil::createFormDataUpload(solverAddress, postURI,
00120                   osilFileName,  theOSiLFile, boundaryName);
00121     // send the soap to the HTTP server
00122     std::cout << "SEND THE FILE " << std::endl;
00123     //std::cout << theHTTPPOST << std::endl;
00124     uploadResult = WSUtil::sendSOAPMessage( theHTTPPOST, solverAddress, solverPortNumber);
00125     return uploadResult;
00126 }//end solve
00127 
00128 
00129 bool OSSolverAgent::send(string osil, string osol)
00130 {
00131     string theSOAP;
00132     string sendResult;
00133     bool useCDATA = true;
00134     // CreateSOAPMessage inputs
00135     int numInputs = 2;
00136     string smethod = "send";
00137     string msInputs[2];
00138     // package up the inputs
00139     // first run them through SAOPify, e.g. replace < with &lt; etc.
00140     msInputs[0] = WSUtil::SOAPify( osil, useCDATA) ;
00141     msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00142     string msInputNames[2] = {"osil", "osol"};
00143     string sSoapAction = "OSSolverService#send";
00144     // create the soap
00145     theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00146                                         smethod, msInputs, msInputNames, sSoapAction);
00147     // send the soap to the HTTP server
00148     sendResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00149     // strip out the OSxL that we want from the SOAP envelope
00150     sendResult = WSUtil::getOSxL(sendResult, "send");
00151     // desoapify the result -- i.e. replace &lt; with <  etc.
00152     useCDATA = false;
00153     sendResult = WSUtil::deSOAPify( sendResult, useCDATA);
00154     if( sendResult.find("true") != string::npos ) return true;
00155     else return false;
00156 }//end send
00157 
00158 string OSSolverAgent::getJobID(string osol)
00159 {
00160     string sjobID = "";
00161     string getJobIDResult;
00162     string theSOAP;
00163     bool useCDATA = true;
00164     // CreateSOAPMessage inputs
00165     int numInputs = 1;
00166     string smethod = "getJobID";
00167     string msInputs[1];
00168     // package up the inputs
00169     // first run them through SAOPify, e.g. replace < with &lt; etc.
00170     msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00171     string msInputNames[1] = {"osol"};
00172     string sSoapAction = "OSSolverService#getJobID";
00173     // create the soap
00174     theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00175                                         smethod, msInputs, msInputNames, sSoapAction);
00176     // send the soap to the HTTP server
00177     getJobIDResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00178     // strip out the OSxL that we want from the SOAP envelope
00179     getJobIDResult =  WSUtil::getOSxL(getJobIDResult, "getJobID");
00180     // desoapify the result -- i.e. replace &lt; with <  etc.
00181     useCDATA = false;
00182     sjobID = WSUtil::deSOAPify( getJobIDResult, useCDATA);
00183 
00184     return sjobID;
00185 }//end getJobID
00186 
00187 string OSSolverAgent::retrieve(string osol)
00188 {
00189     string sOSrL;
00190     string retrieveResult;
00191     string theSOAP;
00192     bool useCDATA = true;
00193     // CreateSOAPMessage inputs
00194     int numInputs = 1;
00195     string smethod = "retrieve";
00196     string msInputs[1];
00197     // package up the inputs
00198     // first run them through SAOPify, e.g. replace < with &lt; etc.
00199     msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00200     string msInputNames[1] = {"osol"};
00201     string sSoapAction = "OSSolverService#retrieve";
00202     // create the soap
00203     theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00204                                         smethod, msInputs, msInputNames, sSoapAction);
00205     // send the soap to the HTTP server
00206     retrieveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00207     // strip out the OSxL that we want from the SOAP envelope
00208     retrieveResult =  WSUtil::getOSxL(retrieveResult, "retrieve");
00209     // desoapify the result -- i.e. replace &lt; with <  etc.
00210     useCDATA = false;
00211     sOSrL = WSUtil::deSOAPify( retrieveResult, useCDATA);
00212     return sOSrL;
00213 }//end retrieve
00214 
00215 string OSSolverAgent::kill(string osol)
00216 {
00217     string sOSpL;
00218     string killResult;
00219     string theSOAP;
00220     bool useCDATA = true;
00221     // CreateSOAPMessage inputs
00222     int numInputs = 1;
00223     string smethod = "kill";
00224     string msInputs[1];
00225     // package up the inputs
00226     // first run them through SAOPify, e.g. replace < with &lt; etc.
00227     msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00228     string msInputNames[1] = {"osol"};
00229     string sSoapAction = "OSSolverService#kill";
00230     // create the soap
00231     theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00232                                         smethod, msInputs, msInputNames, sSoapAction);
00233     // send the soap to the HTTP server
00234     killResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00235     // strip out the OSxL that we want from the SOAP envelope
00236     killResult =  WSUtil::getOSxL( killResult, "kill");
00237     // desoapify the result -- i.e. replace &lt; with <  etc.
00238     useCDATA = false;
00239     sOSpL = WSUtil::deSOAPify( killResult, useCDATA);
00240     return sOSpL;
00241 }//end kill
00242 
00243 string OSSolverAgent::knock(string ospl, string osol)
00244 {
00245     string sOSpL;
00246     string theSOAP;
00247     string knockResult;
00248     bool useCDATA = true;
00249     // CreateSOAPMessage inputs
00250     int numInputs = 2;
00251     string smethod = "knock";
00252     string msInputs[2];
00253     // package up the inputs
00254     // first run them through SAOPify, e.g. replace < with &lt; etc.
00255     msInputs[0] = WSUtil::SOAPify( ospl, useCDATA) ;
00256     msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00257     string msInputNames[2] = {"ospl", "osol"};
00258     string sSoapAction = "OSSolverService#knock";
00259     // create the soap
00260     theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00261                                         smethod, msInputs, msInputNames, sSoapAction);
00262     // send the soap to the HTTP server
00263     knockResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00264 
00265     // strip out the OSxL that we want from the SOAP envelope
00266     knockResult = WSUtil::getOSxL( knockResult, "knock");
00267     // desoapify the result -- i.e. replace &lt; with <  etc.
00268     useCDATA = false;
00269     sOSpL = WSUtil::deSOAPify( knockResult, useCDATA);
00270     return sOSpL;
00271 }//end knock

Generated on Thu Nov 10 03:05:47 2011 by  doxygen 1.4.7