My Project
OSLindoSolver.cpp
Go to the documentation of this file.
1/* $Id$ */
16#include "OSLindoSolver.h"
17#include "OSiLReader.h"
18#include "OSInstance.h"
19#include "OSFileUtil.h"
20#include "OSOutput.h"
21#include "OSErrorClass.h"
22
23#include "OSDataStructures.h"
24#include "OSParameters.h"
25#include "OSMathUtil.h"
26
27#include "CoinTime.hpp"
28
29
30#ifdef HAVE_CTIME
31# include <ctime>
32#else
33# ifdef HAVE_TIME_H
34# include <time.h>
35# else
36# error "don't have header file for time"
37# endif
38#endif
39#include <iostream>
40#include <sstream>
41#include<vector>
42#include <map>
43
44using std::cout;
45using std::endl;
46using std::ostringstream;
47
48#define DEBUG
49#ifndef __LINDOI_H__
50#define __LINDOI_H__
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56 int CALLTYPE LSwriteMPIFile(pLSmodel pModel, char *pszFname);
57
58#ifdef __cplusplus
59}
60#endif
61
62#endif /* ifndef __ILINDO_H__ */
63
64#define LINDO_OP_CODE_CONVERSION \
65 std::map<int, int> nlNodeIdxLindo;\
66 nlNodeIdxLindo[OS_PLUS] = EP_PLUS; \
67 nlNodeIdxLindo[OS_SUM] = EP_SUM; \
68 nlNodeIdxLindo[OS_MINUS] = EP_MINUS; \
69 nlNodeIdxLindo[OS_NEGATE] = EP_NEGATE; \
70 nlNodeIdxLindo[OS_TIMES] = EP_MULTIPLY; \
71 nlNodeIdxLindo[OS_DIVIDE] = EP_DIVIDE; \
72 nlNodeIdxLindo[OS_POWER] = EP_POWER; \
73 nlNodeIdxLindo[OS_SQRT] = EP_SQRT; \
74 nlNodeIdxLindo[OS_LN] = EP_LN; \
75 nlNodeIdxLindo[OS_EXP] = EP_EXP; \
76 nlNodeIdxLindo[OS_NUMBER] = EP_PUSH_NUM; \
77 nlNodeIdxLindo[OS_VARIABLE] = EP_PUSH_VAR;\
78 nlNodeIdxLindo[OS_IF] = EP_IF; \
79 nlNodeIdxLindo[OS_ABS] = EP_ABS; \
80 nlNodeIdxLindo[OS_MAX] = EP_MAX; \
81 nlNodeIdxLindo[OS_MIN] = EP_MIN; \
82 nlNodeIdxLindo[OS_SQUARE] = EP_SQR; \
83 nlNodeIdxLindo[OS_SIN] = EP_SIN; \
84 nlNodeIdxLindo[OS_COS] = EP_COS;
85
87 m_osilreader( NULL),
88 pEnv_( NULL),
89 pModel_( NULL),
90 m_miSlackIdx( NULL),
91 m_iNumberNewSlacks( 0),
92 m_mdRhsValue( NULL),
93 m_mcRowType( NULL),
94 m_mdVarLB( NULL),
95 m_mdVarUB( NULL),
96 m_mdConLB( NULL),
97 m_mdConUB( NULL),
98 m_mmcVarName( NULL),
99 m_msVarName( NULL),
100 m_msConName( NULL),
101 m_mcVarType( NULL),
102 m_mdObjConstant( 0),
103 osrlwriter( NULL),
104 cpuTime( 0)
105
106{
107#ifndef NDEBUG
108 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "Lindo constructor called\n");
109#endif
110 osrlwriter = new OSrLWriter();
111}
112
114{
115#ifndef NDEBUG
116 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "Lindo destructor called\n");
117#endif
118 //delete[] m_mdRhsValue ;
119 //delete[] m_mdVarLB ;
120 //delete[] m_mdVarUB ;
121 delete[] m_mmcVarName ;
122
123 m_mdConLB = NULL;
124 m_mdConUB = NULL;
125 m_msVarName = NULL;
126 m_mcVarType = NULL;
127 m_mcRowType = NULL;
128 m_msConName = NULL;
129#ifndef NDEBUG
131#endif
132 LSdeleteEnv(&pEnv_);
133 delete[] m_miSlackIdx;
134 m_miSlackIdx = NULL;
135 delete[] m_mdRhsValue;
136 m_mdRhsValue = NULL;
137 delete osrlwriter;
138 osrlwriter = NULL;
139 delete osresult;
140 osresult = NULL;
141 if(m_osilreader != NULL) delete m_osilreader;
142 m_osilreader = NULL;
143 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_info, "Lindo Solver garbage collection done\n");
144
145}
146
147
149{
150 try
151 {
152 osresult = new OSResult();
153 if(osil.length() == 0 && osinstance == NULL) throw ErrorClass("there is no instance");
154 OSiLReader* osilreader = NULL;
155 bool newOSiLReader = false;
156 if(osinstance == NULL)
157 {
158 osilreader = new OSiLReader();
159 osinstance = osilreader->readOSiL( osil);
160 newOSiLReader = true;
161
162 }
163
164 OSiLWriter osilwriter;
165
167 {
168#ifndef NDEBUG
170 "HERE I AM 1 !!!!!!!!!!!!!!!!!!!\n");
171#endif
173 osinstance->addConstraint(0, "dummyConstraint", 0, 0, 0);
174#ifndef NDEBUG
176 "HERE I AM 2 !!!!!!!!!!!!!!!!!!!\n");
178 osilwriter.writeOSiL( osinstance));
179#endif
180 }
181 if(osinstance->getVariableNumber() < 0)throw ErrorClass("Cannot have a negative number of decision variables");
182#ifndef NDEBUG
184 "Start process variables !!!!!!!!!\n");
185#endif
186 if( !processVariables() ) throw ErrorClass("failed processing variables");
187#ifndef NDEBUG
189 "Finish process variables !!!!!!!!!\n");
191 "Start process constraints !!!!!!!!!\n");
192#endif
193 if( !processConstraints() ) throw ErrorClass("failed processing constraints");
194#ifndef NDEBUG
196 "Finish process constraints !!!!!!!!!\n");
198 "Start generateLindoModel() !!!!!!!!!\n");
199#endif
200 if( !generateLindoModel()) throw ErrorClass("failed generating Lindo model");
201#ifndef NDEBUG
203 "Finish generateLindoModel() !!!!!!!!!\n");
204#endif
205 if(m_iNumberNewSlacks > 0 && !addSlackVars()) throw ErrorClass("failed adding slack variables");
207 && !processNonlinearExpressions()) throw ErrorClass("failed adding nonlinear terms");
208 this->bCallbuildSolverInstance = true ;
209 //dataEchoCheck();
210 }
211 catch(const ErrorClass& eclass)
212 {
217 throw ErrorClass( osrl) ;
218 }
219}//end buildSolverInstance()
220
221
222
224{
225 try
226 {
227
228 }
229 catch(const ErrorClass& eclass)
230 {
235 throw ErrorClass( osrl) ;
236 }
237}//end setSolverOptions()
238
239
241{
242 if( this->bCallbuildSolverInstance == false) buildSolverInstance();
243 try
244 {
245 double start = CoinCpuTime();
246 if( optimize() != true) throw ErrorClass("problem optimizing model");
247 cpuTime = CoinCpuTime() - start;
251 }
252 catch(const ErrorClass& eclass)
253 {
257 throw ErrorClass( osrl) ;
258 }
259}// end solve
260
262{
263 int i;
265 try
266 {
267
268
275
276 for(i = 0; i < osinstance->getConstraintNumber(); i++)
277 {
278 switch( m_mcRowType[ i] )
279 {
280 case 'E':
281 m_mdRhsValue[ i] = m_mdConUB[ i];
282 //m_mdRhsValue[ i] = m_mdConUB[ i]; Kipp: get constant
283 // Add method in OSInstance get constraint constant
284 break;
285 case 'L':
286 m_mdRhsValue[ i] = m_mdConUB[ i];
287 break;
288 case 'G':
289 m_mdRhsValue[ i] = m_mdConLB[ i];
290 break;
291 case 'U':
292 throw ErrorClass("LINDO cannot handle unbounded constraints");
293 break;
294 case 'R':
295 // we have a range constraint -- LINDO does not allow this -- a variable must be added later
296 m_mdRhsValue[ i] = m_mdConUB[ i] ;
297 m_mcRowType[ i] = 'E';
300 break;
301 }
302 }
303 return true;
304 }
305 catch(const ErrorClass& eclass)
306 {
310 throw ;
311 }
312} // end processConstraints
313//
315{
316 std::ostringstream outStr;
317
318 /* the following is LINDO specific -- make up
319 for the fact that lindo does not like upper and lower bounds on consraints
320 this is not needed in the COIN Interface
321 */
322 if(m_iNumberNewSlacks <= 0) return false;
323 int i;
324 ostringstream varName;
325 char* p;
326 std::string tmpstring;
327 char* pachVartypes = new char[m_iNumberNewSlacks];
328 char** paszVarnames = new char*[m_iNumberNewSlacks];
329 int* paiAcols = new int[m_iNumberNewSlacks + 1];
330 int* pacAcols = NULL;
331 double* padAcoef = new double[m_iNumberNewSlacks];
332 int* paiArows = new int[m_iNumberNewSlacks];
333 double* padC = new double[m_iNumberNewSlacks];
334 double* padL = NULL;
335 double* padU = new double[m_iNumberNewSlacks];
336 for(i = 0; i < m_iNumberNewSlacks; i++)
337 {
338 pachVartypes[ i] = 'C';
339 varName << "xyzabc_" ;
340 varName << i ;
341 varName << '\0';
342 tmpstring = varName.str();
343 p = new char[tmpstring.size() + 1];
344 strcpy(p, tmpstring.c_str());
345 char ch;
346 ch = ' ';
347 // a LINDO kludge
348 if( m_iNumberNewSlacks == 1) paszVarnames[i] = &ch;
349 else paszVarnames[i] = p;
350 varName << "";
351 paiAcols[ i] = i;
352 padAcoef[ i] = 1.0;
353 paiArows[ i] = m_miSlackIdx[ i];
354 padC[ i] = 0.0;
355 padU[ i] = m_mdConUB[ m_miSlackIdx[ i]] - m_mdConLB[ m_miSlackIdx[ i]];
356 if(padU[ i] - padC[i]< 0) return false;
357 }
359#ifndef NDEBUG
360 outStr.str("");
361 outStr.clear();
362 outStr << "The number of new slack variables is: " << m_iNumberNewSlacks << endl;
363 for(i = 0; i < m_iNumberNewSlacks; i++)
364 {
365 outStr << paszVarnames[ i] << endl;
366 }
368#endif
369
370 if(!LSaddVariables(pModel_, m_iNumberNewSlacks, pachVartypes, paszVarnames, paiAcols,
371 pacAcols, padAcoef, paiArows, padC, padL, padU))
372 {
373 if(m_iNumberNewSlacks > 0)
374 {
375 //
376 delete[] paiAcols;
377 delete[] padAcoef;
378 delete[] paiArows;
379 delete[] padC;
380 delete[] padU;
381
382 // another LINDO kludge
383 if( m_iNumberNewSlacks == 1)
384 {
385 delete paszVarnames;
386 delete pachVartypes;
387 }
388 else
389 {
390 for(i = 0; i < m_iNumberNewSlacks; i++) delete[] paszVarnames[i];
391 delete[] paszVarnames;
392 delete[] pachVartypes;
393 }
394 }
395 return true;
396 }
397 else
398 {
399 return false;
400 }
401} // end addSlackVars()
402
403
405{
406 int i;
407 try
408 {
413 for(i = 0; i < osinstance->getVariableNumber(); i++)
414 {
416 }
417 //fix for Stefan
418 for(i = 0; i < osinstance->getVariableNumber() ; i++)
419 {
420 if( osinstance->getVariableTypes()[ i] == 'B')
421 {
422 m_mdVarUB[ i] = 1.0;
423 }
424 }
425
426 return true;
427 }
428 catch(const ErrorClass& eclass)
429 {
433 throw ;
434 }
435} // end processVariables
436
437
438
440{
441 std::ostringstream outStr;
442
443 // Generate the LINDO model
444 /* declare an instance of the LINDO environment object */
445 /* >>> Step 1 <<< Create a LINDO environment. Note:
446 MY_LICENSE_KEY must be defined in license.h to
447 be the license key shipped with your software. */
448 char *MY_LICENSE_KEY = NULL;
449 MY_LICENSE_KEY = getenv( "LINDOAPI_LICENSE_FILE");
450 try
451 {
452 pEnv_ = LScreateEnv ( &m_iLindoErrorCode, MY_LICENSE_KEY);
453 lindoAPIErrorCheck("There was an Error Creating the LINDO environment");
454 /* >>> Step 2 <<< Create a model in the environment. */
455 pModel_ = LScreateModel ( pEnv_, &m_iLindoErrorCode);
456 lindoAPIErrorCheck("There was an Error Creating the LINDO Model");
457 /* >>> Step 3 <<< Specify the model.
458 To specify our model, we make a call to LSloadLPData,
459 passing it:
460 - A pointer to the model which we are specifying(pModel_)
461 - The number of constraints in the model
462 - The number of variables in the model
463 - The direction of the optimization (i.e. minimize or maximize)
464 - The value of the constant term in the objective (may be zero)
465 - The coefficients of the objective function
466 - The right-hand sides of the constraints
467 - The types of the constraints
468 - The number of nonzeros in the constraint matrix
469 - The indices of the first nonzero in each column
470 - The length of each column
471 - The nonzero coefficients
472 - The row indices of the nonzero coefficients
473 - Simple upper and lower bounds on the variables
474 */
475 int *colLength = NULL;
476 // Kipp: this is a kludge -- fix later
478 {
479 outStr.str("");
480 outStr.clear();
481 outStr << "LinearConstraintCoefficientNumber = " << osinstance->getLinearConstraintCoefficientNumber() << endl;
483 //
484
485 int iNumFakeNonz = 1;
486 // fake index array
487 int *paiArrayIdx;
488 paiArrayIdx = new int[ 1];
489 paiArrayIdx[ 0] = 0;
490 // fake nonzero array
491 double *padValArray;
492 padValArray = new double[ 1];
493 padValArray[0] = 0;
494 //
495 int *paiArrayBeg;
496 paiArrayBeg = new int[osinstance->getVariableNumber() + 1];
497 paiArrayBeg[0] = 0;
498 for(int kl = 1; kl <= osinstance->getVariableNumber(); kl++)
499 {
500 paiArrayBeg[kl] = 1;
501 }
502 //
503 //
505 ( osinstance->getObjectiveMaxOrMins()[0] == "min")?LS_MIN:LS_MAX ,
509 iNumFakeNonz,
510 paiArrayBeg,
511 colLength, padValArray,
512 paiArrayIdx,
514 lindoAPIErrorCheck("Error with LSloadLPData when the number of nonzeros is 0");
515 }
516 else
517 {
519 ( osinstance->getObjectiveMaxOrMins()[0] == "min")?LS_MIN:LS_MAX ,
526 lindoAPIErrorCheck("Error with LSloadLPData when the number of nonzeros is greater than 0");
527 }
528 m_iLindoErrorCode = LSloadVarType(pModel_, m_mcVarType);
529 lindoAPIErrorCheck("There was an error loading the Lindo Variable Types");
530 return true;
531 }
532 catch( const ErrorClass& eclass)
533 {
537 throw ;
538 }
539} // end generateLindoModel
540
541
543{
544 double *x, *y, *z;
545 int solIdx = 0;
546 ostringstream outStr;
547 std::string *srcost;
548 bool isNonlinear = false;
549 double *drcost;
550 int nSolStatus;
551 std::string description = "";
552 // resultHeader information
553 if(osresult->setSolverInvoked( "LINDO Systems, Inc. Lindo API") != true)
554 throw ErrorClass("OSResult error: setSolverInvoked");
556 throw ErrorClass("OSResult error: setServiceName");
557
559 throw ErrorClass("OSResult error: setInstanceName");
560 //if(osresult->setJobID( osresultdata->jobID) != true)
561 // throw ErrorClass("OSResult error: setJobID");
562 //if(osresult->setGeneralMessage( osresultdata->message) != true)
563 // throw ErrorClass("OSResult error: setGeneralMessage");
565 try
566 {
567 if(osinstance->getObjectiveNumber() <= 0) throw ErrorClass("LINDO NEEDS AN OBJECTIVE FUNCTION");
568
569 if( isNonlinear == true )
570 {
571 //m_iLindoErrorCode = LSoptimize( pModel_, LS_METHOD_FREE, &nSolStatus);
573 "We are using the LINDO Global Optimizer\n");
574 m_iLindoErrorCode = LSsolveGOP(pModel_, &nSolStatus) ;
575 lindoAPIErrorCheck("There was an ERROR in the call to the Optimizer solver");
576 LSgetInfo (pModel_, LS_IINFO_GOP_STATUS, &nSolStatus);
577 }
578 else
579 {
581 "We are using the LINDO LSsolveMIP Optimizer\n");
582 m_iLindoErrorCode = LSsolveMIP( pModel_, &nSolStatus);
583 lindoAPIErrorCheck("There was an ERROR in the call to the MIP solver");
584 }
585 // set basic problem parameters
587 throw ErrorClass("OSResult error: setVariableNumer");
588 if(osresult->setObjectiveNumber( 1) != true)
589 throw ErrorClass("OSResult error: setObjectiveNumber");
591 throw ErrorClass("OSResult error: setConstraintNumber");
592 if(osresult->setSolutionNumber( 1) != true)
593 throw ErrorClass("OSResult error: setSolutionNumer");
594 outStr.str("");
595 outStr.clear();
596 outStr << "Solution Status = " << nSolStatus << endl;
598
600 osresult->setSolutionStatus(solIdx, "optimal", description);
601 x = new double[ osinstance->getVariableNumber() + m_iNumberNewSlacks];
602 srcost = new std::string[ osinstance->getVariableNumber() + m_iNumberNewSlacks];
603 drcost = new double[ osinstance->getVariableNumber() + m_iNumberNewSlacks];
604 for(int i = 0; i < osinstance->getVariableNumber() + m_iNumberNewSlacks; i++)
605 {
606 drcost[i] = 0.0;
607 srcost[i] = "";
608 }
609 y = new double[ osinstance->getConstraintNumber() ];
610 z = new double[1];
611 switch( nSolStatus)
612 {
613 case 1:
614 // an optimal solution is found
616 case 8:
617 // a local optimal solution is found
619 case 2:
621 // an optimal basic solution is also found
622 // get the primal result
624 || (isNonlinear == false) )
625 {
626 m_iLindoErrorCode = LSgetMIPPrimalSolution( pModel_, x);
627 lindoAPIErrorCheck("Error trying to obtain primal solution with integer variables present");
628 }
629
630 else
631 {
632 m_iLindoErrorCode = LSgetPrimalSolution( pModel_, x);
633 lindoAPIErrorCheck("Error trying to obtain primal solution with NO integer variables present");
634 }
636 // Get the dual values result
638 || (isNonlinear == false) )
639 {
640 m_iLindoErrorCode = LSgetMIPDualSolution( pModel_, y);
641 lindoAPIErrorCheck("Error trying to obtain dual solution with integer variables present");
642 }
643 else
644 {
645 m_iLindoErrorCode = LSgetDualSolution( pModel_, y);
646 lindoAPIErrorCheck("Error trying to obtain dual solution with NO integer variables present");
647 }
649 // get the reduced cost result
651 || (isNonlinear == false ) )
652 {
653 //m_iLindoErrorCode = LSgetMIPReducedCosts( pModel_, drcost);
654 //lindoAPIErrorCheck("Error trying to obtain the reduced costs with integer variables present");
655 }
656 else
657 {
658 m_iLindoErrorCode = LSgetReducedCosts( pModel_, drcost);
659 lindoAPIErrorCheck("Error trying to obtain the reduced costs with NO integer variables present");;
660 }
661 // now put the reduced costs into the osrl
662 {
663 int numberOfOtherVariableResult = 1;
664 int otherIdx = 0;
665 // first set the number of Other Variable Results
666 osresult->setNumberOfOtherVariableResults(solIdx, numberOfOtherVariableResult);
667 for(int i = 0; i < osinstance->getVariableNumber() + m_iNumberNewSlacks; i++)
668 {
669 outStr << drcost[i];
670 srcost[ i] = outStr.str();
671 outStr.str("");
672 }
673 osresult->setAnOtherVariableResultDense(solIdx, otherIdx, "reduced costs", "", "the variable reduced costs", srcost);
674 /* Get the value of the objective */
676 || (isNonlinear == false ) )
677 {
678 m_iLindoErrorCode = LSgetInfo( pModel_, LS_DINFO_MIP_OBJ, &z[0]);
679 lindoAPIErrorCheck("Error trying to obtain optimal objective value with integer variables present");
680 }
681 else
682 {
683 LSgetInfo( pModel_, LS_DINFO_GOP_OBJ, &z[0]);
684 lindoAPIErrorCheck("Error trying to obtain optimal objective value with NO integer variables present");
685 }
687 }
688 break;
689 case 3:
690 osresult->setSolutionStatus(solIdx, "infeasible", description);
691 break;
692 case 4:
693 osresult->setSolutionStatus(solIdx, "unbounded", description);
694 break;
695 default:
696 osresult->setSolutionStatus(solIdx, "other", description);
697 }
698
699 delete[] x;
700 delete[] y;
701 delete[] z;
702 delete[] srcost;
703 delete[] drcost;
704 return true;
705 }
706 catch(const ErrorClass& eclass)
707 {
708
712 throw ;
713 }
714} //end optimize
715
716
718{
721 "WE ARE PROCESSING QUADRATIC TERMS\n");
722 try
723 {
724 if(nQCnnz <= 0)return false;
725 std::map<std::string, double> mapQuadraticAdjustMap;
726 std::map<std::string, double>::iterator mapPointer;
727
728 int i;
729 int iVarOneIndex, iVarTwoIndex;
730 int iRowIndex;
731 std::string sKey;
732 double dValue;
733
734 int iStringPostionOne, iStringPostionTwo;
735
736 int* paiQCrows = osinstance->getQuadraticTerms()->rowIndexes;
737 int* paiQCcols1 = osinstance->getQuadraticTerms()->varOneIndexes;
738 int* paiQCcols2 = osinstance->getQuadraticTerms()->varTwoIndexes;
739 double* padQCcoef = osinstance->getQuadraticTerms()->coefficients;
740 std::ostringstream ostrRow, ostr1, ostr2;
741 std::string sIndexRow, sIndex1, sIndex2;
742
743 for ( i = 0; i < nQCnnz; i++)
744 {
745 iRowIndex = paiQCrows[i];
746
747 if (iRowIndex >= -1)
748 {
749 iVarOneIndex = (paiQCcols1[i] >= paiQCcols2[i])?paiQCcols2[i]:paiQCcols1[i];
750 iVarTwoIndex = (paiQCcols1[i] <= paiQCcols2[i])?paiQCcols2[i]:paiQCcols1[i];
751 ostrRow << iRowIndex;
752 ostr2<<iVarTwoIndex;
753 ostr1<<iVarOneIndex;
754 sIndexRow = ostrRow.str();
755 sIndex2 = ostr2.str();
756 sIndex1 = ostr1.str();
757
758 ostrRow.str("");
759 ostr2.str("");
760 ostr1.str("");
761
762 sKey = sIndexRow + "," + sIndex1 + "," + sIndex2;
763
764 mapPointer = mapQuadraticAdjustMap.find(sKey);
765 if (mapPointer != mapQuadraticAdjustMap.end())
766 {
767 dValue = mapPointer->second;
768 dValue += padQCcoef[i];
769 mapQuadraticAdjustMap[sKey] = dValue;
770 }
771 else
772 {
773 mapQuadraticAdjustMap[sKey] = padQCcoef[i];
774 }
775 }
776 }
777
778 int iNumberOfQuadraticTerms = 0;
779 for (mapPointer = mapQuadraticAdjustMap.begin(); mapPointer != mapQuadraticAdjustMap.end(); ++mapPointer)
780 {
781 sKey = mapPointer->first;
782 dValue = mapPointer->second;
783 iStringPostionOne = sKey.find_first_of(',');
784 iStringPostionTwo = sKey.find_last_of(',');
785
786 iRowIndex = atoi(sKey.substr(0, iStringPostionOne).c_str());
787 iVarOneIndex = atoi(sKey.substr(iStringPostionOne + 1, iStringPostionTwo).c_str());
788 iVarTwoIndex = atoi(sKey.substr(iStringPostionTwo + 1).c_str());
789
790 if ( iVarOneIndex == iVarTwoIndex)
791 {
792 dValue *= 2;
793 }
794
795 paiQCrows[iNumberOfQuadraticTerms] = iRowIndex;
796 paiQCcols1[iNumberOfQuadraticTerms] = iVarOneIndex;
797 paiQCcols2[iNumberOfQuadraticTerms] = iVarTwoIndex;
798
799 padQCcoef[iNumberOfQuadraticTerms] = dValue ;//lindo' AD assumes that there is a 0.5 in front of quadratic matrix.
800 iNumberOfQuadraticTerms ++;
801 }
802
803 if(!LSloadQCData(pModel_, nQCnnz, paiQCrows, paiQCcols1,
804 paiQCcols2, padQCcoef)) return true;
805 else return false;
806 }
807 catch(const ErrorClass& eclass)
808 {
812 throw ;
813 }
814} // end processQuadraticTerms
815
816
817
819{
820 std::ostringstream outStr;
821
823 "PROCESS NONLINEAR TERMS\n");
825 //osinstance->addQTermsToExpressionTree();
826 outStr.str("");
827 outStr.clear();
828 outStr << "The number of objectives with nonlinear terms is: "
830 outStr << "The number of constraints with nonlinear terms is: "
831 << osinstance->getNumberOfNonlinearConstraints() << endl << endl << endl;
833 // first convert OS numbering of operators to Lindo numbering of operators.
834 // this is done by the method setnlNodeIdxLindo()
835 // execute the Macro that does the conversion between LINDO and OS op codes
842 std::map<double, int> mapNewNumber;
843
845 std::map<double, int>::iterator pos;
846
852 std::vector<int> insList;
853
854
860 std::map<int, OSExpressionTree*> allExpTrees;
861
867 std::vector<OSnLNode*> postFixVec;
868
870 std::map<int, OSExpressionTree*>::iterator posTree;
871
881 int *piObjSense = NULL;
882
886 double *padVarLowerBounds = NULL;
887
891 double *padVarUpperBounds = NULL;
892
894 double *padVarval = NULL;
895
899 char *pachVarType = NULL;
900
903 char *pachConType = NULL;
904
906 int iNumNonlinearNonz = 0;
907
909 double *padNonlinearNonz = NULL;
910
912 int iNumberOfNonlinearConstraints = osinstance->getNumberOfNonlinearConstraints();
913
917 int *paiConsBegin = NULL;
918 if(iNumberOfNonlinearConstraints > 0) paiConsBegin = new int[ iNumberOfNonlinearConstraints];
919
923 int *paiConsLength = NULL;
924 if(iNumberOfNonlinearConstraints > 0) paiConsLength = new int[ iNumberOfNonlinearConstraints];
925
927 int iNumberOfNonlinearObjectives = osinstance->getNumberOfNonlinearObjectives();
928
932 int *paiObjsBegin = NULL;
933 if(iNumberOfNonlinearObjectives > 0) paiObjsBegin = new int[ iNumberOfNonlinearObjectives];
934
938 int *paiObjsLength = NULL;
939 if(iNumberOfNonlinearObjectives > 0) paiObjsLength = new int[ iNumberOfNonlinearObjectives];
940
941
947 int iNumberOfNewVariables = 0;
948
950 int *paiInsList;
951
953 int iInstListLength = 0;
954
956 int *paiNonlinearConIndex = NULL;
957 if(iNumberOfNonlinearConstraints > 0) paiNonlinearConIndex = new int[ iNumberOfNonlinearConstraints];
958
959 // end of local variable definition
960 try
961 {
962 int i;
963 // initialize constraint and objectives counters
964 int iCountObjs = 0;
965 int iCountCons = 0;
966 // get all of the expression trees for each constraint and objective
968 // now use an iterator to loop over all the expression trees
969 for(posTree = allExpTrees.begin(); posTree != allExpTrees.end(); ++posTree)
970 {
971 outStr.str("");
972 outStr.clear();
973 outStr << "HERE IS EXPRESSION TREE " << posTree->first << endl;
975 // get the expression tree and put it into a postfix vector of OSnLNodes
976 postFixVec = posTree->second->m_treeRoot->getPostfixFromExpressionTree();
977 int iVecSize = postFixVec.size();
978 int iNodeID;
979 if(iVecSize > 0)
980 {
981 for(i = 0; i < iVecSize; i++)
982 {
983 iNodeID = postFixVec[i]->inodeInt;
984 switch (iNodeID)
985 {
986 case OS_SUM: // the sum token
987 insList.push_back( nlNodeIdxLindo[ OS_SUM] );
988 insList.push_back( postFixVec[i]->inumberOfChildren);
990 break;
991 case OS_MAX: // the sum token
992 insList.push_back( nlNodeIdxLindo[ OS_MAX] );
993 insList.push_back( postFixVec[i]->inumberOfChildren);
995 break;
996 case OS_PRODUCT: // the product token
997 throw ErrorClass("Error: OS_PRODUCT operator not supported by Lindo");
998 break;
999 case OS_NUMBER: // the number token
1000 OSnLNodeNumber *numNode;
1001 insList.push_back( EP_PUSH_NUM );
1002 numNode = (OSnLNodeNumber*)postFixVec[i];
1003 pos = mapNewNumber.find( numNode->value);
1004 if(pos == mapNewNumber.end() )
1005 {
1006 outStr.str("");
1007 outStr.clear();
1008 outStr << "FOUND A NEW NUMBER " << numNode->value << endl;
1010 insList.push_back( iNumNonlinearNonz);
1011 mapNewNumber[ numNode->value] = iNumNonlinearNonz++;
1012 }
1013 else insList.push_back( pos->second);
1014 break;
1015 case OS_VARIABLE: // the variable token
1016 OSnLNodeVariable *varNode;
1017 insList.push_back( EP_PUSH_VAR );
1018 varNode = (OSnLNodeVariable*)postFixVec[i];
1019 insList.push_back( varNode->idx );
1020 // If the variable has a coefficient other than 1 push back
1021 // that coefficient plus a multiplier
1022 if(varNode->coef != 1)
1023 {
1024 //push back the number
1025 insList.push_back( EP_PUSH_NUM );
1026 pos = mapNewNumber.find( varNode->coef);
1027 if(pos == mapNewNumber.end() )
1028 {
1029 outStr.str("");
1030 outStr.clear();
1031 outStr << "FOUND A NEW NUMBER " << varNode->coef << endl;
1033 insList.push_back( iNumNonlinearNonz);
1034 mapNewNumber[ varNode->coef] = iNumNonlinearNonz++;
1035 }
1036 else insList.push_back( pos->second);
1037 insList.push_back( EP_MULTIPLY);
1038 }
1039 break;
1040 default:
1041 insList.push_back( nlNodeIdxLindo[iNodeID] );
1042 break;
1043 }
1044 }//end for loop over the postfix vector of OSnLNodes
1045 //take appropriate action depending on whether we have a nonlinear obj or constraint
1046 if(posTree->first < 0)
1047 {
1048 // process an objective function
1049 // Kipp: what to do if more than one objective function -- issue an error
1050 paiObjsBegin[ iCountObjs] = iInstListLength;
1051 paiObjsLength[ iCountObjs] = insList.size() - iInstListLength;
1052 iInstListLength = insList.size();
1053 iCountObjs++;
1054 }
1055 else
1056 {
1057 // process a constraint
1058 paiConsBegin[ iCountCons] = iInstListLength;
1059 paiConsLength[ iCountCons] = insList.size() - iInstListLength;
1060 paiNonlinearConIndex[ iCountCons] = posTree->first;
1061 outStr.str("");
1062 outStr.clear();
1063 outStr << "CONSTRAINT ILIST LENGTH = " << iInstListLength << endl;
1065 iInstListLength = insList.size();
1066 iCountCons++;
1067 }
1068 }
1069 postFixVec.clear();
1070 }//end for loop over the expression trees
1071 /* Number of real number constants */
1072 padNonlinearNonz = new double[ iNumNonlinearNonz];
1073 outStr.str("");
1074 outStr.clear();
1075 for(pos = mapNewNumber.begin(); pos != mapNewNumber.end(); ++pos)
1076 {
1077 padNonlinearNonz[ pos->second] = pos->first;
1078 outStr << "INDEX = " << pos->second << " NUMBER = " << pos->first << endl;
1079 }
1081 // read instructions into a Lindo pointer
1082 paiInsList = new int[ iInstListLength];
1083 copy(insList.begin(), insList.end(), paiInsList);
1084
1085 //
1086 // Lindo Solver variables
1087 int nLinearz, nAutoDeriv;
1088 /* Set linearization level, before a call to LSloadInstruct.
1089 * If not specified, the solver will decide */
1090 nLinearz = 1;
1091 m_iLindoErrorCode = LSsetModelIntParameter (pModel_,
1092 LS_IPARAM_NLP_LINEARZ, nLinearz);
1093 lindoAPIErrorCheck("Error trying to set the LS_IPARAM_NLP_LINEARZ parameter");
1094
1095 /* Set up automatic differentiation, before a call to
1096 * LSloadInstruct. If not specified, the numerical derivative
1097 * will be applied */
1098 nAutoDeriv = 1;
1099 m_iLindoErrorCode = LSsetModelIntParameter (pModel_,
1100 LS_IPARAM_NLP_AUTODERIV, nAutoDeriv);
1101 lindoAPIErrorCheck("Error trying to set the LS_IPARAM_NLP_AUTODERIV parameter");
1102#ifndef NDEBUG
1103 outStr.str("");
1104 outStr.clear();
1105 outStr << "iNumberOfNonlinearConstraints= " << iNumberOfNonlinearConstraints << std::endl;
1106 outStr << "iNumberOfNonlinearObjectives= " << iNumberOfNonlinearObjectives << std::endl;
1107 outStr << "iNumberOfNewVariables = " << iNumberOfNewVariables << std::endl;
1108 outStr << "iNumNonlinearNonz = " << iNumNonlinearNonz << std::endl;
1109 outStr << "piObjSense = " << "NULL" << std::endl ;
1110 outStr << "pachConType = " << "NULL" << std::endl ;
1111 outStr << "pachVarType = " << "NULL" << std::endl ;
1112 int kl;
1113 outStr << "Here is the instruction list" << std::endl;
1114 for(kl = 0; kl < iInstListLength; kl++)
1115 {
1116 outStr << "instruction list num " << paiInsList[ kl] << endl;
1117 }
1118 outStr << "Number of terms in instruction list " << iInstListLength << std::endl;
1119 outStr << "Here are the constraint indices " << std::endl;
1120 for(kl = 0; kl < iNumberOfNonlinearConstraints; kl++)
1121 {
1122 outStr << "con idx " << paiNonlinearConIndex[ kl] << endl;
1123 }
1124 outStr << "Here come the nonlinear nonzeros " << std::endl;
1125 for(kl = 0; kl < iNumNonlinearNonz; kl++)
1126 {
1127 outStr << "nonz value = " << padNonlinearNonz[ kl] << endl;
1128 }
1129 outStr << "padVarval = " << "NULL" << std::endl ;
1130 for(kl = 0; kl < iNumberOfNonlinearObjectives; kl++)
1131 {
1132 outStr << "obj inst begin = " << paiObjsBegin[ kl] << endl;
1133 }
1134 for(kl = 0; kl < iNumberOfNonlinearObjectives; kl++)
1135 {
1136 outStr << "obj inst list length = " << paiObjsLength[ kl] << endl;
1137 }
1138 for(kl = 0; kl < iNumberOfNonlinearConstraints; kl++)
1139 {
1140 outStr << "constraint inst begin = " << paiConsBegin[ kl] << endl;
1141 }
1142 for(kl = 0; kl < iNumberOfNonlinearConstraints; kl++)
1143 {
1144 outStr << "constraints inst list length = " << paiConsLength[ kl] << endl;
1145 }
1146 outStr << "padVarLowerBounds = " << "NULL" << std::endl ;
1147 outStr << "padUpperBounds = " << "NULL" << std::endl ;
1149#endif
1150 m_iLindoErrorCode = LSaddInstruct (pModel_, iNumberOfNonlinearConstraints,
1151 iNumberOfNonlinearObjectives, iNumberOfNewVariables, iNumNonlinearNonz,
1152 piObjSense, pachConType, pachVarType, paiInsList, iInstListLength, paiNonlinearConIndex,
1153 padNonlinearNonz, padVarval, paiObjsBegin, paiObjsLength, paiConsBegin,
1154 paiConsLength, padVarLowerBounds, padVarUpperBounds);
1155 lindoAPIErrorCheck("Error trying to call LSaddInstruct");
1156 // Kipp: do some garbage collection
1157 // get rid of the local news
1158 //mapNewNumber.~map();
1159 if( iNumberOfNonlinearConstraints > 0) delete[] paiConsBegin;
1160 if( iNumberOfNonlinearConstraints > 0) delete[] paiConsLength;
1161 if( iNumberOfNonlinearObjectives > 0) delete[] paiObjsBegin;
1162 if( iNumberOfNonlinearObjectives > 0) delete[] paiObjsLength;
1163 if( iNumberOfNonlinearConstraints > 0) delete[] paiNonlinearConIndex;
1164 if( iNumNonlinearNonz > 0) delete[] padNonlinearNonz;
1165 if( iInstListLength > 0) delete[] paiInsList;
1166 mapNewNumber.clear();
1167 //mapNewNumber.~map();
1168 allExpTrees.clear();
1169 //allExpTrees.~map();
1170 insList.clear();
1171 //insList.~vector<int>();
1172 postFixVec.clear();
1173 //postFixVec.~vector<OSnLNode*>();
1174 return true;
1175 }
1176 catch(const ErrorClass& eclass)
1177 {
1179 osresult->setGeneralStatusType( "error");
1181 throw ;
1182 }
1183}//end processNonlinearExpressions
1184
1185
1186
1188{
1189 int i;
1190 std::ostringstream outStr;
1191
1192 // print out problem parameters
1193 outStr << "This is problem: " << osinstance->getInstanceName() << endl;
1194 outStr << "The problem source is: " << osinstance->getInstanceSource() << endl;
1195 outStr << "The problem description is: " << osinstance->getInstanceDescription() << endl;
1196 outStr << "number of variables = " << osinstance->getVariableNumber() << endl;
1197 outStr << "number of Rows = " << osinstance->getConstraintNumber() << endl;
1198
1199 // print out the variable information
1200 if(osinstance->getVariableNumber() > 0)
1201 {
1202 for(i = 0; i < osinstance->getVariableNumber(); i++)
1203 {
1204 if(osinstance->getVariableNames() != NULL) outStr << "variable Names " << osinstance->getVariableNames()[ i] << endl;
1205 if(osinstance->getVariableTypes() != NULL) outStr << "variable Types " << osinstance->getVariableTypes()[ i] << endl;
1206 if(osinstance->getVariableLowerBounds() != NULL) outStr << "variable Lower Bounds " << osinstance->getVariableLowerBounds()[ i] << endl;
1207 if(osinstance->getVariableUpperBounds() != NULL) outStr << "variable Upper Bounds " << osinstance->getVariableUpperBounds()[i] << endl;
1208 }
1209 }
1210
1211 // print out objective function information
1213 {
1214 if( osinstance->getObjectiveMaxOrMins()[0] == "min") outStr << "problem is a minimization" << endl;
1215 else outStr << "problem is a maximization" << endl;
1216 for(i = 0; i < osinstance->getVariableNumber(); i++)
1217 {
1218 outStr << "OBJ COEFFICIENT = " << osinstance->getDenseObjectiveCoefficients()[0][i] << endl;
1219 }
1220 }
1221 // print out constraint information
1223 {
1224 for(i = 0; i < osinstance->getConstraintNumber(); i++)
1225 {
1226 if(osinstance->getConstraintNames() != NULL) outStr << "row name = " << osinstance->getConstraintNames()[i] << endl;
1227 if(osinstance->getConstraintLowerBounds() != NULL) outStr << "row lower bound = " << osinstance->getConstraintLowerBounds()[i] << endl;
1228 if(osinstance->getConstraintUpperBounds() != NULL) outStr << "row upper bound = " << osinstance->getConstraintUpperBounds()[i] << endl;
1229 }
1230 }
1231
1232 // print out linear constraint data
1233 outStr << endl;
1234 outStr << "number of nonzeros = " << osinstance->getLinearConstraintCoefficientNumber() << endl;
1236 {
1237 for(i = 0; i <= osinstance->getVariableNumber(); i++)
1238 {
1239 outStr << "Start Value = " << osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[ i] << endl;
1240 }
1241 outStr << endl;
1242 for(i = 0; i < osinstance->getLinearConstraintCoefficientNumber(); i++)
1243 {
1244 outStr << "Index Value = " << osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes[i] << endl;
1245 outStr << "Nonzero Value = " << osinstance->getLinearConstraintCoefficientsInColumnMajor()->values[i] << endl;
1246 }
1247 }
1248 // print out quadratic data
1249 outStr << "number of qterms = " << osinstance->getNumberOfQuadraticTerms() << endl;
1250 for(int i = 0; i < osinstance->getNumberOfQuadraticTerms(); i++)
1251 {
1252 outStr << "Row Index = " << osinstance->getQuadraticTerms()->rowIndexes[i] << endl;
1253 outStr << "Var Index 1 = " << osinstance->getQuadraticTerms()->varOneIndexes[ i] << endl;
1254 outStr << "Var Index 2 = " << osinstance->getQuadraticTerms()->varTwoIndexes[ i] << endl;
1255 outStr << "Coefficient = " << osinstance->getQuadraticTerms()->coefficients[ i] << endl;
1256 }
1258
1259} // end dataEchoCheck
1260
1261void LindoSolver::lindoAPIErrorCheck(std::string errormsg)
1262{
1263 try
1264 {
1265 ostringstream outStr;
1266 std::string error = errormsg;
1267 char lindoerrormsg[LS_MAX_ERROR_MESSAGE_LENGTH];
1268 if(m_iLindoErrorCode != 0)
1269 {
1270 outStr << endl;
1271 error = "LINDO ERROR: "+ error;
1272 outStr << error << endl;
1273 outStr << "LINDO ERROR NUMBER: " << m_iLindoErrorCode << endl;
1274 if( pEnv_ != NULL) LSgetErrorMessage(pEnv_, m_iLindoErrorCode, lindoerrormsg);
1275 error = lindoerrormsg;
1276 outStr << "LINDO ERROR MESSAGE: " << error;
1277 outStr << endl;
1278 error = outStr.str();
1279 throw ErrorClass( error);
1280 }
1281 }
1282 catch(const ErrorClass& eclass)
1283 {
1284 throw ErrorClass( eclass.errormsg);
1285 }
1286}// end lindoAPIErrorCheck
1287
1288
1289
1290
1291
1292
const OSSmartPtr< OSOutput > osoutput
Definition OSOutput.cpp:39
#define LINDO_OP_CODE_CONVERSION
int CALLTYPE LSwriteMPIFile(pLSmodel pModel, char *pszFname)
std::string OSgetVersionInfo()
int numberOfConstraints
numberOfConstraints is the number of constraints in the instance
Definition OSInstance.h:264
std::string osrl
osrl holds the solution or result of the model
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
bool bCallbuildSolverInstance
bCallbuildSolverInstance is set to true if buildSolverService has been called
std::string osil
osil holds the problem instance as a std::string
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object
used for throwing exceptions.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Constraints * constraints
constraints is a pointer to a Constraints object
Objectives * objectives
objectives is a pointer to a Objectives object
std::string * m_msVarName
m_msVarName holds an array of variable std::string names.
bool generateLindoModel()
create the LINDO environment and read the problem into the internal LINDO data structures
void dataEchoCheck()
use this for debugging, print out the instance that the solver thinks it has and compare this with th...
int m_iLindoErrorCode
m_iErrorCode is a variable for LINDO error codes
LindoSolver()
the LindoSolver class constructor
bool processConstraints()
read the OSiL instance constraints and put these into the LINDO API constraints
bool addSlackVars()
LINDO does not handle constraints with upper and lower bounds this method is part of kludge where we ...
char * m_mcRowType
m_mcRowType - E for equality, L for less than, G for greater than – used if we do not store rows usin...
double * m_mdRhsValue
m_mdRhsValue is used to the store the constraint rhs if we do not use row upper and lower bounds
bool processVariables()
read the OSiL instance variables and put these into the LINDO API variables
pLSmodel pModel_
declare an instance of the LINDO model object
OSiLReader * m_osilreader
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed
virtual void buildSolverInstance()
buildSolverInstance is a virtual function – the actual solvers will implement their own buildSolverIn...
pLSenv pEnv_
declare an instance of the LINDO environment object
OSrLWriter * osrlwriter
osrlwriter object used to write osrl from an OSResult object
~LindoSolver()
the LindoSolver class destructor
char * m_mcVarType
m_vcVarType holds an array of variable types (character), e.g.
bool processNonlinearExpressions()
read the nonlinear terms in the model
double * m_mdConUB
m_mdRhs holds an array of the constraint upper bounds.
std::string * m_msConName
m_msConName holds an array of constraint std::string names.
char ** m_mmcVarName
m_mmcVarName holds an array of char arrays.
void lindoAPIErrorCheck(std::string errormsg)
Lindo's generalized error Reporting function.
virtual void setSolverOptions()
The implementation of the virtual functions.
bool processQuadraticTerms()
read the quadratic terms in the model
bool optimize()
invoke the Lindo API solver
virtual void solve()
solve results in an instance being read into the Lindo data structures and optimized
int m_iNumberNewSlacks
m_iNumberNewSlacks is the number of slack variables to add
int * m_miSlackIdx
because LINDO API does not take row ranges we need some extra stuff m_miSlackIdx indexes the rows tha...
double * m_mdVarLB
m_mdLb holds an array of variable lower bounds.
double * m_mdConLB
m_mdLhs holds an array of the constraint lower bounds.
double * m_mdVarUB
m_mdUb holds an array of variable upper bounds.
double * getConstraintLowerBounds()
Get constraint lower bounds.
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
double * getVariableUpperBounds()
Get variable upper bounds.
bool setConstraintNumber(int number)
set the number of constraints.
int getNumberOfIntegerVariables()
getNumberOfIntegerVariables
bool addConstraint(int index, std::string name, double lowerBound, double upperBound, double constant)
add a constraint.
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
int getNumberOfNonlinearObjectives()
std::string getInstanceDescription()
Get instance description.
std::string getInstanceSource()
Get instance source.
int getConstraintNumber()
Get number of constraints.
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
char * getVariableTypes()
Get variable initial values.
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
InstanceData * instanceData
A pointer to an InstanceData object.
int getNumberOfNonlinearExpressions()
Get number of nonlinear expressions.
QuadraticTerms * getQuadraticTerms()
Get all the quadratic terms in the instance.
double * getObjectiveConstants()
Get objective constants.
double * getVariableLowerBounds()
Get variable lower bounds.
int getVariableNumber()
Get number of variables.
std::string * getVariableNames()
Get variable names.
std::string getInstanceName()
Get instance name.
char * getConstraintTypes()
Get constraint types.
std::string * getConstraintNames()
Get constraint names.
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
bool initializeNonLinearStructures()
Initialize the data structures for the nonlinear API.
double * getConstraintUpperBounds()
Get constraint upper bounds.
int getObjectiveNumber()
Get number of objectives.
std::map< int, ScalarExpressionTree * > getAllNonlinearExpressionTreesMod()
int getNumberOfNonlinearConstraints()
The Result Class.
Definition OSResult.h:2549
bool setGeneralMessage(std::string message)
Set the general message.
bool setSolutionNumber(int number)
set the number of solutions.
bool setInstanceName(std::string instanceName)
Set instance name.
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution's objective values, where i equals the given solution index.
bool setNumberOfOtherVariableResults(int solIdx, int numberOfOtherVariableResults)
Set the [i]th optimization solution's other (non-standard/solver specific) variable-related results,...
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
bool setPrimalVariableValuesDense(int solIdx, double *x)
Set the [i]th optimization solution's primal variable values, where i equals the given solution index...
bool setServiceName(std::string serviceName)
Set service name.
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
bool setVariableNumber(int variableNumber)
Set the variable number.
bool setTime(double time)
Set time.
bool setDualVariableValuesDense(int solIdx, double *y)
Set the [i]th optimization solution's dual variable values, where i equals the given solution index.
bool setAnOtherVariableResultDense(int solIdx, int otherIdx, std::string name, std::string value, std::string description, std::string *s)
Set the [i]th optimization solution's other (non-standard/solver specific)variable-related results,...
bool setSolutionStatus(int solIdx, std::string type, std::string description)
Set the [i]th optimization solution status, where i equals the given solution index.
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
Used to read an OSiL string.
Definition OSiLReader.h:38
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
Take an OSInstance object and write a string that validates against the OSiL schema.
Definition OSiLWriter.h:30
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
The OSnLNodeNumber Class.
Definition OSnLNode.h:1263
double value
value is the value of the number
Definition OSnLNode.h:1266
The OSnLNodeVariable Class.
Definition OSnLNode.h:1479
int idx
idx is the index of the variable
Definition OSnLNode.h:1488
double coef
coef is an option coefficient on the variable, the default value is 1.0
Definition OSnLNode.h:1485
Take an OSResult object and write a string that validates against OSrL.
Definition OSrLWriter.h:31
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
Definition OSInstance.h:201
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
Definition OSInstance.h:205
int * varTwoIndexes
varTwoIndexes holds an integer array of the second variable indexes of all the quadratic terms.
Definition OSGeneral.h:450
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
Definition OSGeneral.h:440
double * coefficients
coefficients holds a double array all the quadratic term coefficients.
Definition OSGeneral.h:455
int * varOneIndexes
varOneIndexes holds an integer array of the first variable indexes of all the quadratic terms.
Definition OSGeneral.h:445
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
Definition OSGeneral.h:258
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
Definition OSGeneral.h:252
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
Definition OSGeneral.h:264
#define OS_PRODUCT
#define OS_SUM
#define OS_MAX
#define OS_VARIABLE
@ ENUM_OUTPUT_LEVEL_debug
@ ENUM_OUTPUT_LEVEL_trace
@ ENUM_OUTPUT_LEVEL_error
@ ENUM_OUTPUT_LEVEL_info
#define OS_NUMBER
@ ENUM_OUTPUT_AREA_OSSolverInterfaces