00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Opt.h"
00021 #include <stdlib.h>
00022
00023 #include <glpk.h>
00024
00025
00026
00027 #include "Agent_base.h"
00028 #include "Agent_space.h"
00029 #include "RegData.h"
00030 #include "Pixel.h"
00031 #include "ModelObject.h"
00032 #include "ThreadManager.h"
00033 #include "Scheduler.h"
00034
00035 using namespace std;
00036
00037 Opt::Opt(ThreadManager* MTHREAD_h, Agent_base* AGENT_h){
00038 MTHREAD=MTHREAD_h;
00039 AGENT=AGENT_h;
00040 z=0;
00041 stat=0;
00042 }
00043
00044 Opt::~Opt(){
00045
00046 }
00047
00051 void
00052 Opt::update(){
00053 updateActivities();
00054 updateResourceNames();
00055 updateResourceValues();
00056
00057 refreshGUI();
00058 }
00059
00097 void
00098 Opt::updateActivities(){
00099 int nPlots;
00100 Agent_space* currentAgent;
00101
00102 vector <Pixel* > plots;
00103 currentAgent = dynamic_cast<Agent_space*> (AGENT);
00104
00105 if (currentAgent){
00106 plots = currentAgent->getPlots(PLOTS_ALL);
00107 nPlots = plots.size();
00108 }
00109 else{
00110 nPlots=0;
00111 }
00112
00113
00114
00115 vector<RegActivities*> actMoulds = MTHREAD->RD->getRegActivities();
00116 vector<ModelObject*> objects = MTHREAD->RD->getObjectsDefinitionVector();
00117
00118 ACTS.clear();
00119
00120
00121 for (uint i=0;i<actMoulds.size();i++){
00122 if(actMoulds.at(i)->getSpatiallyExplicit()){
00123 vector <int> requiredLandUseCodes = actMoulds.at(i)->getRequiredLandUseCodes();
00124 string requiredObjectOnPlot = actMoulds.at(i)->getRequiredObjectOnPlot();
00125 string landUseCodesToken;
00126
00127 for (uint j=0;j<requiredLandUseCodes.size();j++){
00128 landUseCodesToken = landUseCodesToken + " " + i2s(requiredLandUseCodes.at(j));
00129 }
00130
00131 for (uint j=0;j<plots.size();j++){
00132 unsigned int z;
00133
00134 string lusecode = d2s(plots.at(j)->getDoubleValue("landUse"));
00135 bool fulfilledObjectRequirement = false;
00136 z = landUseCodesToken.find(lusecode);
00137
00138 if (z!=string::npos){
00139
00140 if (requiredObjectOnPlot != ""){
00141 vector <string> pixelsObjects = plots.at(j)->getIncludedObjectNames();
00142 for (uint y=0;y<pixelsObjects.size();y++){
00143 if ( pixelsObjects.at(y) == requiredObjectOnPlot) {
00144 fulfilledObjectRequirement = true;
00145 break;
00146 }
00147 }
00148 }
00149 else {
00150 fulfilledObjectRequirement = true;
00151 }
00152 if (fulfilledObjectRequirement){
00153
00154 matrixActivities ACT;
00155 ACT.name=actMoulds.at(i)->getName();
00156 double plotID=plots.at(j)->getID();
00157 string plotIDs = d2s(plotID);
00158 ACT.fullName=actMoulds.at(i)->getName()+"_on_"+plotIDs;
00159
00160 ACT.isInvest = false;
00161 ACT.q = 0;
00162 ACT.objValue = actMoulds.at(i)->getMatrixGrossMargin();
00163 vector <double> matrixCoefficients = actMoulds.at(i)->getMatrixCoefficients();
00164 ACT.values = matrixCoefficients;
00165 for (uint y=0;y<plots.size();y++){
00166 ACT.values.push_back(0);
00167 }
00168 ACT.values.at(matrixCoefficients.size()+j)=1;
00169 ACT.plotHost=plots.at(j);
00170 ACT.actMould = actMoulds.at(i);
00171 ACT.objMould = 0;
00172 bool test=AGENT->filterActivity(&ACT);
00173 if(test) ACTS.push_back(ACT);
00174 }
00175 }
00176 }
00177 }
00178 else {
00179
00180 matrixActivities ACT;
00181 ACT.name=actMoulds.at(i)->getName();
00182 ACT.fullName=actMoulds.at(i)->getName();
00183 ACT.isInvest = false;
00184 ACT.q = 0;
00185 ACT.objValue = actMoulds.at(i)->getMatrixGrossMargin();
00186 vector <double> matrixCoefficients = actMoulds.at(i)->getMatrixCoefficients();
00187 ACT.values = matrixCoefficients;
00188 for (uint y=0;y<plots.size();y++){
00189 ACT.values.push_back(0);
00190 }
00191 ACT.plotHost=0;
00192 ACT.actMould = actMoulds.at(i);
00193 ACT.objMould = 0;
00194 bool test=AGENT->filterActivity(&ACT);
00195 if(test) ACTS.push_back(ACT);
00196 }
00197 }
00198
00199
00200 for (uint i=0;i<objects.size();i++){
00201 if(objects.at(i)->getSpatiallyExplicit()){
00202 vector <int> requiredLandUseCodes = objects.at(i)->getRequiredLandUseCodes();
00203 string landUseCodesToken;
00204
00205 for (uint j=0;j<requiredLandUseCodes.size();j++){
00206 landUseCodesToken = landUseCodesToken + " " + i2s(requiredLandUseCodes.at(j));
00207 }
00208
00209 for (uint j=0;j<plots.size();j++){
00210
00211 unsigned int z;
00212 string lusecode = d2s(plots.at(j)->getDoubleValue("landUse"));
00213 z = landUseCodesToken.find(lusecode);
00214
00215 if (z!=string::npos){
00216
00217 vector <string> pixelsObjects = plots.at(j)->getIncludedObjectNames();
00218 bool fulfilledObjectRequirement = true;
00219 for (uint y=0;y<pixelsObjects.size();y++){
00220 if ( pixelsObjects.at(y) == objects.at(i)->getName()) {
00221 fulfilledObjectRequirement = false;
00222 break;
00223 }
00224 }
00225 if (fulfilledObjectRequirement){
00226
00227 matrixActivities ACT;
00228 ACT.name=objects.at(i)->getName();
00229 ACT.fullName=objects.at(i)->getName()+"_on_"+d2s(plots.at(j)->getID());
00230 ACT.isInvest = true;
00231 ACT.q = 0;
00232 ACT.objValue = objects.at(i)->getMatrixGrossMargin();
00233 vector <double> matrixCoefficients = objects.at(i)->getMatrixCoefficients();
00234 ACT.values = matrixCoefficients;
00235 for (uint y=0;y<plots.size();y++){
00236 ACT.values.push_back(0);
00237 }
00238 ACT.values.at(matrixCoefficients.size()+j)=1;
00239 ACT.plotHost=plots.at(j);
00240 ACT.actMould = 0;
00241 ACT.objMould = objects.at(i);
00242 bool test=AGENT->filterActivity(&ACT);
00243 if(test) ACTS.push_back(ACT);
00244 }
00245 }
00246 }
00247 }
00248 else {
00249
00250 matrixActivities ACT;
00251 ACT.name=objects.at(i)->getName();
00252 ACT.fullName=objects.at(i)->getName();
00253 ACT.isInvest = true;
00254 ACT.q = 0;
00255 ACT.objValue = objects.at(i)->getMatrixGrossMargin();
00256 vector <double> matrixCoefficients = objects.at(i)->getMatrixCoefficients();
00257 ACT.values = matrixCoefficients;
00258 for (uint y=0;y<plots.size();y++){
00259 ACT.values.push_back(0);
00260 }
00261 ACT.plotHost=0;
00262 ACT.actMould = 0;
00263 ACT.objMould = objects.at(i);
00264 bool test=AGENT->filterActivity(&ACT);
00265 if(test) ACTS.push_back(ACT);
00266 }
00267 }
00268 };
00269
00274 void
00275 Opt::updateResourceNames(){
00276
00277 resourceNames.clear();
00278 resourceNames= MTHREAD->RD->getResourceNames();
00279
00280 int nPlots;
00281 Agent_space* currentAgent;
00282 vector <Pixel* > plots;
00283 currentAgent = dynamic_cast<Agent_space*> (AGENT);
00284 if (currentAgent){
00285 plots=currentAgent->getPlots(PLOTS_ALL);
00286 nPlots=plots.size();
00287 }
00288 else{
00289 nPlots=0;
00290 }
00291 for (uint i=0;i<plots.size();i++){
00292 string name = "Plot_"+d2s(plots.at(i)->getID());
00293 resourceNames.push_back(name);
00294 }
00295 };
00296
00308 void
00309 Opt::updateResourceValues(){
00310
00311 resourceValues.clear();
00312 resourceValues.resize(resourceNames.size(),0);
00313
00314
00315 for (int i=0;i<MTHREAD->RD->getResourceSize();i++){
00316 resourceValues.at(i) = AGENT->getResource(resourceNames.at(i));
00317 }
00318
00319 for (uint i=MTHREAD->RD->getResourceSize();i<resourceNames.size();i++){
00320 resourceValues[i] = 1;
00321 }
00322
00323 };
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 void
00425 Opt::debug(string debugMessage, bool useCallCounter){
00426 int callCounter=0;
00427 string directoryToSave = MTHREAD->RD->getBaseDirectory()+MTHREAD->RD->getOutputDirectory()+"debugMatrices/";
00428 string filenameToSave = "";
00429 if (useCallCounter){
00430 filenameToSave = "ag"+i2s(AGENT->getAgentUniqueID())+"_-_"+i2s(MTHREAD->SCD->getYear())+"_-_"+i2s(callCounter)+"_-_"+debugMessage+".csv";
00431 } else {
00432 filenameToSave = "ag"+i2s(AGENT->getAgentUniqueID())+"_-_"+i2s(MTHREAD->SCD->getYear())+"_-_"+debugMessage+".csv";
00433 }
00434 string fullFilename = directoryToSave+filenameToSave;
00435 ofstream out;
00436 out.open(fullFilename.c_str(), ios::out);
00437 if (!out){ msgOut(MSG_ERROR,"Error in opening the file "+fullFilename+".");}
00438 out << "*** Debug Matrix ***"<< "\n\n";
00439 out << "Optimal Value (Z);Stat;Year;Agent;Mould;Msg" << "\n";
00440 out << z << ";" << stat << ";" << MTHREAD->SCD->getYear() << ";" << AGENT->getAgentUniqueID() << ";" << AGENT->getMouldLocalID() << ";" << debugMessage << "\n\n";
00441
00442
00443 out << ";RESOURCES;;";
00444 for (uint i=0;i<ACTS.size();i++){
00445 out << ACTS.at(i).fullName << ";" ;
00446 }
00447 out << "\n";
00448
00449 out << "type -->;;;";
00450 for (uint i=0;i<ACTS.size();i++){
00451 out << ACTS.at(i).isInvest << ";" ;
00452 }
00453 out << "\n";
00454
00455 out << "gm -->;;;";
00456 for (uint i=0;i<ACTS.size();i++){
00457 out << ACTS.at(i).objValue << ";" ;
00458 }
00459 out << "\n";
00460
00461 out << "opt q -->;;;";
00462 for (uint i=0;i<ACTS.size();i++){
00463 out << ACTS.at(i).q << ";" ;
00464 }
00465 out << "\n";
00466 out << "Resources:;"<<"\n";
00467
00468 for (uint i=0;i<resourceNames.size();i++){
00469 out << resourceNames.at(i) << ";" ;
00470 out << resourceValues.at(i) << ";;" ;
00471 for (uint j=0;j<ACTS.size();j++){
00472 out << ACTS.at(j).values.at(i) << ";" ;
00473 }
00474 out << "\n";
00475 }
00476 out << "\n\n";
00477
00478 out.close();
00479 callCounter++;
00480 };
00481
00487 void
00488 Opt::solve(){
00489
00490 solveGlpk();
00491 return;
00492
00493 }
00494
00495
00501 void
00502 Opt::solveGlpk(){
00503 bool fixedLand;
00504 int resourceSize;
00505
00506
00507
00508 fixedLand = MTHREAD->RD->getBoolSetting("fullLandUsage", DATA_NOW);
00509 resourceSize = MTHREAD->RD->getResourceSize();
00510
00511
00512
00513 glp_prob* lpglpk;
00514 glp_iocp* parm;
00515 lpglpk = glp_create_prob();
00516 glp_set_prob_name(lpglpk, "farmerProblem");
00517 glp_set_obj_dir(lpglpk, GLP_MAX);
00518
00519
00520 glp_term_out(GLP_OFF);
00521
00522 parm = new glp_iocp;
00523
00524 glp_init_iocp(parm);
00525
00526 parm->msg_lev = GLP_MSG_OFF;
00527
00528
00529
00530
00531
00532
00533
00534 int maxNZSpace = 2;
00535 for (uint j=1;j<ACTS.size()+1;j++){
00536 for (uint i=1;i<resourceNames.size()+1;i++){
00537 if (ACTS[j-1].values[i-1] != 0){
00538 maxNZSpace++;
00539 }
00540 }
00541 }
00542
00543 if(maxNZSpace >=120000){
00544 msgOut(MSG_WARNING, "Agent "+i2s(AGENT->getAgentUniqueID())+" has a huge matrix.. on MS Windows system this could lead to a crash.. u are advised!");
00545 }
00546
00547
00548
00549 int ia[maxNZSpace], ja[maxNZSpace];
00550 double ar[maxNZSpace];
00551
00552
00553 int nRowsCurrentProblem = glp_get_num_rows(lpglpk);
00554 int nColsCurrentProblem = glp_get_num_cols(lpglpk);
00555
00556 if(nRowsCurrentProblem>0){
00557 int num[nRowsCurrentProblem];
00558 for(int i=1;i<nRowsCurrentProblem+1;i++){
00559 num[i]=i;
00560 }
00561 glp_del_rows(lpglpk, nRowsCurrentProblem, num);
00562 }
00563 if(nColsCurrentProblem>0){
00564 int num[nColsCurrentProblem];
00565 for(int i=1;i<nColsCurrentProblem+1;i++){
00566 num[i]=i;
00567 }
00568 glp_del_cols(lpglpk, nColsCurrentProblem, num);
00569 }
00570
00571
00572 glp_add_rows(lpglpk, resourceNames.size());
00573
00574
00575 for (uint i=1;i<resourceNames.size()+1;i++){
00576 if (((int)i)<resourceSize+1 || !fixedLand ){
00577 glp_set_row_bnds(lpglpk, i, GLP_UP, 0.0, resourceValues[i-1]);
00578 }
00579 else {
00580
00581 glp_set_row_bnds(lpglpk, i, GLP_FX, resourceValues[i-1], resourceValues[i-1]);
00582 }
00583 }
00584
00585
00586
00587 glp_add_cols(lpglpk, ACTS.size());
00588 for (uint i=1;i<ACTS.size()+1;i++){
00589 glp_set_obj_coef(lpglpk, i, ACTS[i-1].objValue);
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 glp_set_col_bnds(lpglpk, i, GLP_LO, 0.0, 0.0);
00600
00601 }
00602
00603
00604
00605 int nz_counter=1;
00606 for (uint j=1;j<ACTS.size()+1;j++){
00607 for (uint i=1;i<resourceNames.size()+1;i++){
00608 if (ACTS[j-1].values[i-1] != 0){
00609 ia[nz_counter] = i;
00610 ja[nz_counter] = j;
00611 ar[nz_counter] = ACTS[j-1].values[i-1];
00612 nz_counter++;
00613 }
00614 }
00615 }
00616
00617 glp_load_matrix(lpglpk, nz_counter-1, ia, ja, ar);
00618
00619
00620 for (uint i=0;i<ACTS.size();i++){
00621 if (ACTS[i].isInvest){
00622 glp_set_col_kind(lpglpk, i+1, GLP_IV);
00623 }
00624 }
00625
00626
00627
00628
00629
00630
00631 stat=lpx_simplex(lpglpk);
00632
00633
00634
00635
00636
00637 stat=lpx_integer(lpglpk);
00638
00639
00640
00641
00642
00643
00644 z = glp_mip_obj_val(lpglpk);
00645
00646
00647 for (uint i=0; i<ACTS.size(); i++){
00648 ACTS[i].q = glp_mip_col_val(lpglpk, i+1);
00649 }
00650
00651
00652
00653
00654 glp_delete_prob(lpglpk);
00655 delete parm;
00656
00657 }
00658
00665 void
00666 Opt::saveToCache(){
00667 cachedZ = z;
00668 for (uint i=0;i<ACTS.size();i++){
00669 ACTS[i].cachedQ = ACTS[i].q;
00670 }
00671 cachedStat = stat;
00672 }
00673
00680 void
00681 Opt::restoreFromCache(){
00682 z = cachedZ;
00683 for (uint i=0;i<ACTS.size();i++){
00684 ACTS[i].q = ACTS[i].cachedQ;
00685 }
00686 stat = cachedStat;
00687 }
00688
00697 void
00698 Opt::addPixel(const Pixel* px_h){
00699
00700 Agent_space* currentAgent;
00701 currentAgent = dynamic_cast<Agent_space*> (AGENT);
00702
00703
00704
00705 if (currentAgent){
00706
00707 double plotId;
00708 vector<RegActivities*> actMoulds;
00709 vector<ModelObject*> objects;
00710 double landUse;
00711 string lusecode;
00712
00713
00714 plotId=px_h->getID();
00715 actMoulds = MTHREAD->RD->getRegActivities();
00716 objects = MTHREAD->RD->getObjectsDefinitionVector();
00717 lusecode = d2s(px_h->getDoubleValue("landUse"));
00718
00719
00720 actsAddedOnLastPixel=0;
00721 resourceNames.push_back("Plot_"+d2s(plotId));
00722 resourceValues.push_back(1);
00723
00724 for (uint i=0;i<ACTS.size();i++){
00725 ACTS.at(i).values.push_back(0);
00726 }
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738 for (uint i=0;i<actMoulds.size();i++){
00739 if(actMoulds.at(i)->getSpatiallyExplicit()){
00740 vector <int> requiredLandUseCodes = actMoulds.at(i)->getRequiredLandUseCodes();
00741 string requiredObjectOnPlot = actMoulds.at(i)->getRequiredObjectOnPlot();
00742 string landUseCodesToken;
00743
00744 for (uint j=0;j<requiredLandUseCodes.size();j++){
00745 landUseCodesToken = landUseCodesToken + " " + i2s(requiredLandUseCodes.at(j));
00746 }
00747 unsigned int z;
00748 bool fulfilledObjectRequirement = false;
00749 z = landUseCodesToken.find(lusecode);
00750
00751 if (z!=string::npos){
00752
00753 if (requiredObjectOnPlot != ""){
00754 vector <string> pixelsObjects = px_h->getIncludedObjectNames();
00755 for (uint y=0;y<pixelsObjects.size();y++){
00756 if ( pixelsObjects.at(y) == requiredObjectOnPlot) {
00757 fulfilledObjectRequirement = true;
00758 break;
00759 }
00760 }
00761 }
00762 else {
00763 fulfilledObjectRequirement = true;
00764 }
00765 if (fulfilledObjectRequirement){
00766
00767 matrixActivities ACT;
00768 ACT.name=actMoulds.at(i)->getName();
00769 ACT.fullName=actMoulds.at(i)->getName()+"_on_"+d2s(px_h->getID());
00770 ACT.isInvest = false;
00771 ACT.q = 0;
00772 ACT.objValue = actMoulds.at(i)->getMatrixGrossMargin();
00773 vector <double> matrixCoefficients = actMoulds.at(i)->getMatrixCoefficients();
00774 ACT.values = matrixCoefficients;
00775 for (int y=0;y<currentAgent->getNPlots();y++){
00776 ACT.values.push_back(0);
00777 }
00778 ACT.values.push_back(1);
00779 ACT.plotHost=px_h;
00780 ACT.actMould = actMoulds.at(i);
00781 ACT.objMould = 0;
00782 bool test=AGENT->filterActivity(&ACT);
00783 if(test) ACTS.push_back(ACT);
00784 actsAddedOnLastPixel++;
00785
00786 }
00787 }
00788 }
00789 }
00790
00791
00792
00793 for (uint i=0;i<objects.size();i++){
00794 if(objects.at(i)->getSpatiallyExplicit()){
00795 vector <int> requiredLandUseCodes = objects.at(i)->getRequiredLandUseCodes();
00796 string landUseCodesToken;
00797
00798 for (uint j=0;j<requiredLandUseCodes.size();j++){
00799 landUseCodesToken = landUseCodesToken + " " + i2s(requiredLandUseCodes.at(j));
00800 }
00801
00802 unsigned int z;
00803 string lusecode = d2s(px_h->getDoubleValue("landUse"));
00804 z = landUseCodesToken.find(lusecode);
00805
00806 if (z!=string::npos){
00807
00808 vector <string> pixelsObjects = px_h->getIncludedObjectNames();
00809 bool fulfilledObjectRequirement = true;
00810 for (uint y=0;y<pixelsObjects.size();y++){
00811 if ( pixelsObjects.at(y) == objects.at(i)->getName()) {
00812 fulfilledObjectRequirement = false;
00813 break;
00814 }
00815 }
00816 if (fulfilledObjectRequirement){
00817
00818 matrixActivities ACT;
00819 ACT.name=objects.at(i)->getName();
00820 ACT.fullName=objects.at(i)->getName()+"_on_"+d2s(px_h->getID());
00821 ACT.isInvest = true;
00822 ACT.q = 0;
00823 ACT.objValue = objects.at(i)->getMatrixGrossMargin();
00824 vector <double> matrixCoefficients = objects.at(i)->getMatrixCoefficients();
00825 ACT.values = matrixCoefficients;
00826 for (int y=0;y<currentAgent->getNPlots();y++){
00827 ACT.values.push_back(0);
00828 }
00829 ACT.values.push_back(1);
00830 ACT.plotHost=px_h;
00831 ACT.actMould = 0;
00832 ACT.objMould = objects.at(i);
00833 bool test=AGENT->filterActivity(&ACT);
00834 if(test) ACTS.push_back(ACT);
00835 actsAddedOnLastPixel++;
00836
00837 }
00838 }
00839 }
00840 }
00841
00842 }
00843 };
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00874
00875
00876
00877
00878
00879
00886 void
00887 Opt::removeLastAddedPixel(){
00888
00889 int temp[1+1];
00890 temp[0] = resourceNames.size();
00891 temp[1] = resourceNames.size();
00892
00893 resourceNames.pop_back();
00894 resourceValues.pop_back();
00895
00896
00897 for (uint i=0;i<ACTS.size();i++){
00898 ACTS.at(i).values.pop_back();
00899 }
00900
00901 for (int i=0;i<actsAddedOnLastPixel;i++){
00902 temp[0] = ACTS.size();
00903 temp[1] = ACTS.size();
00904
00905 ACTS.pop_back();
00906 }
00907 }
00908
00909 vector <matrixActivities*>
00910 Opt::getActs(){
00911 vector <matrixActivities*> toReturn;
00912 for (uint i=0;i< ACTS.size();i++){
00913 toReturn.push_back(&ACTS[i]);
00914 }
00915 return toReturn;
00916 }
00917
00918 void
00919 Opt::test(){
00920
00921 glp_prob *lp;
00922 int ia[1+1000], ja[1+1000];
00923 double ar[1+1000], z;
00924 lp = glp_create_prob();
00925 glp_set_prob_name(lp, "sample");
00926 glp_set_obj_dir(lp, GLP_MAX);
00927 glp_add_rows(lp, 3);
00928 glp_set_row_name(lp, 1, "p");
00929 glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);
00930 glp_set_row_name(lp, 2, "q");
00931 glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);
00932 glp_set_row_name(lp, 3, "r");
00933 glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);
00934 glp_add_cols(lp, 3);
00935 glp_set_col_name(lp, 1, "x1");
00936 glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
00937 glp_set_obj_coef(lp, 1, 10.0);
00938 glp_set_col_name(lp, 2, "x2");
00939 glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
00940 glp_set_obj_coef(lp, 2, 6.0);
00941 glp_set_col_name(lp, 3, "x3");
00942 glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
00943 glp_set_obj_coef(lp, 3, 4.0);
00944 ia[1] = 1, ja[1] = 1, ar[1] = 1.0;
00945 ia[2] = 1, ja[2] = 2, ar[2] = 1.0;
00946 ia[3] = 1, ja[3] = 3, ar[3] = 1.0;
00947 ia[4] = 2, ja[4] = 1, ar[4] = 10.0;
00948 ia[5] = 3, ja[5] = 1, ar[5] = 2.0;
00949 ia[6] = 2, ja[6] = 2, ar[6] = 4.0;
00950 ia[7] = 3, ja[7] = 2, ar[7] = 2.0;
00951 ia[8] = 2, ja[8] = 3, ar[8] = 5.0;
00952 ia[9] = 3, ja[9] = 3, ar[9] = 6.0;
00953 glp_load_matrix(lp, 9, ia, ja, ar);
00954
00955 lpx_set_int_parm(lp, LPX_K_MSGLEV, 0);
00956 lpx_simplex(lp);
00957
00958
00959 lpx_set_class(lp, LPX_MIP);
00960
00961 lpx_set_col_kind(lp, 2, LPX_IV);
00962
00963
00964 lpx_integer(lp);
00965 z = lpx_mip_obj_val(lp);
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975 msgOut(MSG_DEBUG, "Optimal value is: "+d2s(z));
00976 glp_delete_prob(lp);
00977 }
00978
00979 double
00980 Opt::getActivityObjValue(string name_h){
00981 for (uint i=0;i<ACTS.size();i++){
00982 if(ACTS.at(i).fullName == name_h){
00983 return ACTS.at(i).objValue;
00984 }
00985 }
00986 msgOut(MSG_ERROR, "Activity "+name_h+" not found. Returning 0");
00987 return 0;
00988 }