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

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

Generated on Mon May 3 03:05:23 2010 by  doxygen 1.4.7