Ignore:
Timestamp:
Oct 2, 2003 1:21:02 PM (17 years ago)
Author:
forrest
Message:

lots of stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pre/Test/ClpMain.cpp

    r210 r212  
    2727#include "ClpDualRowSteepest.hpp"
    2828#include "ClpDualRowDantzig.hpp"
     29#include "ClpLinearObjective.hpp"
    2930#include "ClpPrimalColumnSteepest.hpp"
    3031#include "ClpPrimalColumnDantzig.hpp"
     
    6364  DIRECTORY=301,IMPORT,EXPORT,RESTORE,SAVE,DUALSIMPLEX,PRIMALSIMPLEX,
    6465  MAXIMIZE,MINIMIZE,EXIT,STDIN,UNITTEST,NETLIB_DUAL,NETLIB_PRIMAL,SOLUTION,
    65   TIGHTEN,FAKEBOUND,HELP,PLUSMINUS,NETWORK,ALLSLACK,
     66  TIGHTEN,FAKEBOUND,HELP,PLUSMINUS,NETWORK,ALLSLACK,REVERSE,
    6667
    6768  INVALID=1000
     
    857858    int allowImportErrors=0;
    858859    int keepImportNames=1;
    859     int doIdiot=-2;
     860    int doIdiot=-1;
    860861    int doCrash=0;
    861862    int doSprint=-1;
     
    880881    parameters[numberParameters++]=
    881882      ClpItem("allS!lack","Set basis back to all slack",
    882               ALLSLACK);
    883     parameters[numberParameters-1].setLonghelp
    884       (
    885        ""
     883              ALLSLACK,false);
     884    parameters[numberParameters-1].setLonghelp
     885      (
     886       "Useful for playing around"
    886887       );
    887888    parameters[numberParameters++]=
     
    916917    parameters[numberParameters-1].setLonghelp
    917918      (
    918        "This sets the directory which import, export, saveModel and restoreModel will use"
     919       "This sets the directory which import, export, saveModel and restoreModel will use.\
     920  It is initialized to './'"
    919921       );
    920922    parameters[numberParameters-1].setStringValue(directory);
     
    925927    parameters[numberParameters-1].setLonghelp
    926928      (
    927        ""
     929       "The dual algorithm in Clp is a single phase algorithm as opposed to a two phase\
     930 algorithm where you first get feasible then optimal.  If a problem has both upper and\
     931 lower bounds then it is trivial to get dual feasible by setting non basic variables\
     932 to correct bound.  If the gap between the upper and lower bounds of a variable is more\
     933 than the value of dualBound Clp introduces fake bounds so that it can make the problem\
     934 dual feasible.  This has the same effect as a composite objective function in the\
     935 primal algorithm.  Too high a value may mean more iterations, while too low a bound means\
     936 the code may go all the way and then have to increase the bounds.  OSL had a heuristic to\
     937 adjust bounds, maybe we need that here."
    928938       );
    929939    parameters[numberParameters-1].setDoubleValue(models->dualBound());
     
    936946    parameters[numberParameters-1].setLonghelp
    937947      (
    938        ""
     948       "Clp can use any pivot selection algorithm which the user codes as long as it\
     949 implements the features in the abstract pivot base class.  The Dantzig method is implemented\
     950 to show a simple method but its use is deprecated.  Steepest is the method of choice and there\
     951 are two variants which keep all weights updated but only scan a subset each iteration.\
     952 Partial switches this on while automatic decides at each iteration based on information\
     953 about the factorization."
    939954       );
    940955    parameters[numberParameters++]=
     
    943958    parameters[numberParameters-1].setLonghelp
    944959      (
    945        ""
     960       "This command solves the current model using the dual steepest algorithm.\
     961The time and iterations may be affected by settings such as presolve, scaling, crash\
     962 and also by dual pivot method, fake bound on variables and dual and primal tolerances."
    946963       );
    947964    parameters[numberParameters++]=
     
    951968    parameters[numberParameters-1].setLonghelp
    952969      (
    953        ""
     970       "Normally the default tolerance is fine, but you may want to increase it a\
     971 bit if a dual run seems to be having a hard time"
    954972       );
    955973    parameters[numberParameters-1].setDoubleValue(models->dualTolerance());
     
    959977    parameters[numberParameters-1].setLonghelp
    960978      (
    961        ""
     979       "This stops the execution of Clp, end, exit, quit and stop are synonyms"
    962980       );
    963981    parameters[numberParameters++]=
     
    966984    parameters[numberParameters-1].setLonghelp
    967985      (
    968        ""
     986       "The default is not to use any model which had errors when reading the mps file.\
     987  Setting this to 'on' will allow all errors from which the code can recover\
     988 by ignoring the error."
    969989       );
    970990    parameters[numberParameters++]=
     
    973993    parameters[numberParameters-1].setLonghelp
    974994      (
    975        ""
     995       "This stops the execution of Clp, end, exit, quit and stop are synonyms"
    976996       );
    977997    parameters[numberParameters++]=
     
    9801000    parameters[numberParameters-1].setLonghelp
    9811001      (
    982        ""
     1002       "This will write an MPS format file to the given file name.  It will use the default\
     1003 directory given by 'directory'.  A name of '$' will use the previous value for the name.  This\
     1004 is initialized to 'default.mps'."
    9831005       );
    9841006    parameters[numberParameters-1].setStringValue(exportFile);
     
    9911013    parameters[numberParameters++]=
    9921014      ClpItem("idiot!Crash","Whether to try idiot crash",
    993               -2,200,IDIOT);
    994     parameters[numberParameters-1].setLonghelp
    995       (
    996        ""
     1015              -1,200,IDIOT);
     1016    parameters[numberParameters-1].setLonghelp
     1017      (
     1018       "This is a type of 'crash' which works well on some homogeneous problems.\
     1019 It works best on problems with unit elements and rhs but will do something to any model.  It should only be\
     1020 used before primal.  It can be set to -1 when the code decides for itself whether to use it,\
     1021 0 to switch off or n > 0 to do n passes."
    9971022       );
    9981023    parameters[numberParameters-1].setIntValue(doIdiot);
     
    10021027    parameters[numberParameters-1].setLonghelp
    10031028      (
    1004        ""
     1029       "This will read an MPS format file from the given file name.  It will use the default\
     1030 directory given by 'directory'.  A name of '$' will use the previous value for the name.  This\
     1031 is initialized to '', i.e. it must be set.  If you have libgz then it can read compressed\
     1032 files 'xxxxxxxx.gz'.."
    10051033       );
    10061034    parameters[numberParameters-1].setStringValue(importFile);
     
    10111039    parameters[numberParameters-1].setLonghelp
    10121040      (
    1013        ""
     1041       "It saves space to get rid of names so if you need to you can set this to off."
    10141042       );
    10151043    parameters[numberParameters++]=
     
    10181046    parameters[numberParameters-1].setLonghelp
    10191047      (
    1020        ""
     1048       "If 0 then there should be no output in normal circumstances.  1 is probably the best\
     1049 value for most uses, while 2 and 3 give more information."
    10211050       );
    10221051    parameters[numberParameters-1].setIntValue(models->logLevel());
     
    10261055    parameters[numberParameters-1].setLonghelp
    10271056      (
    1028        ""
     1057       "The default is minimize - use 'maximize' for maximization.\n\
     1058You can also use the parameters 'direction maximize'."
    10291059       );
    10301060    parameters[numberParameters++]=
     
    10511081    parameters[numberParameters-1].setLonghelp
    10521082      (
    1053        ""
     1083       "The default is minimize - use 'maximize' for maximization.\n\
     1084This should only be necessary if you have previously set maximization \
     1085You can also use the parameters 'direction minimize'."
    10541086       );
    10551087    parameters[numberParameters++]=
     
    10581090    parameters[numberParameters-1].append("on");
    10591091    parameters[numberParameters-1].setLonghelp
    1060       (""
     1092      ("The default for the Clp library is to put out messages such as:\n\
     1093   Clp0005 2261  Objective 109.024 Primal infeas 944413 (758)\n\
     1094but this program turns this off to make it look more friendly.  It can be useful\
     1095 to turn them back on if you want to be able 'grep' for particular messages or if\
     1096 you intend to override the behavior of a particular message."
    10611097       );
    10621098    parameters[numberParameters++]=
     
    10711107    parameters[numberParameters-1].setLonghelp
    10721108      (
    1073        ""
     1109       "Clp will go faster if the matrix can be converted to a network.  The matrix\
     1110 operations may be a bit faster with more efficient storage, but the main advantage\
     1111 comes from using a network factorization.  It will probably not be as fast as a \
     1112specialized network code."
    10741113       );
    10751114    parameters[numberParameters++]=
     
    10821121    parameters[numberParameters-1].setLonghelp
    10831122      (
    1084        ""
     1123       "Normally Presolve does 5 passes but you may want to do less to make it\
     1124 more lightweight or do more if improvements are still being made.  As Presolve will return\
     1125 if nothing is being taken out, then you should not need to use this fine tuning."
    10851126       );
    10861127    parameters[numberParameters-1].setIntValue(preSolve);
     
    10951136    parameters[numberParameters-1].setLonghelp
    10961137      (
    1097        ""
     1138       "Perturbation helps to stop cycling, but Clp uses other measures for this.\
     1139  However large problems and especially ones with unit elements and unit rhs or costs\
     1140 benefit from perturbation.  Normally Clp tries to be intelligent, but you can switch this off.\
     1141  The Clp library has this off by default.  This program has it on."
    10981142       );
    10991143    parameters[numberParameters++]=
     
    11021146    parameters[numberParameters-1].setLonghelp
    11031147      (
    1104        ""
     1148       "Clp will go slightly faster if the matrix can be converted so that the elements are\
     1149 not stored and are known to be unit.  The main advantage is memory use.  Clp may automatically\
     1150 see if it can convert the problem so you should not need to use this."
    11051151       );
    11061152    parameters[numberParameters++]=
     
    11201166    parameters[numberParameters-1].append("part!ial");
    11211167    parameters[numberParameters-1].append("steep!est");
    1122     //parameters[numberParameters-1].append("change");
     1168    parameters[numberParameters-1].append("change");
    11231169    parameters[numberParameters-1].setLonghelp
    11241170      (
     
    11551201    parameters[numberParameters-1].setLonghelp
    11561202      (
    1157        ""
     1203       "This stops the execution of Clp, end, exit, quit and stop are synonyms"
    11581204       );
    11591205    parameters[numberParameters++]=
     
    11621208    parameters[numberParameters-1].setLonghelp
    11631209      (
     1210       "This will write an MPS format file to the given file name.  It will use the default\
     1211 directory given by 'directory'.  A name of '$' will use the previous value for the name.  This\
     1212 is initialized to 'default.mps'."
    11641213       ""
    11651214       );
    11661215    parameters[numberParameters-1].setStringValue(restoreFile);
     1216    parameters[numberParameters++]=
     1217      ClpItem("reverse","Reverses sign of objective",
     1218              REVERSE,false);
     1219    parameters[numberParameters-1].setLonghelp
     1220      (
     1221       "Useful for testing if maximization works correctly"
     1222       );
    11671223    parameters[numberParameters++]=
    11681224      ClpItem("save!Model","Save model to binary file",
     
    11701226    parameters[numberParameters-1].setLonghelp
    11711227      (
     1228       "This will write an MPS format file to the given file name.  It will use the default\
     1229 directory given by 'directory'.  A name of '$' will use the previous value for the name.  This\
     1230 is initialized to 'default.mps'."
    11721231       ""
    11731232       );
     
    11771236              "on",SCALING);
    11781237    parameters[numberParameters-1].append("off");
     1238    parameters[numberParameters-1].append("geo!metric");
     1239    parameters[numberParameters-1].append("auto!matic");
    11791240    parameters[numberParameters-1].setLonghelp
    11801241      (
     
    11941255    parameters[numberParameters-1].setLonghelp
    11951256      (
     1257       "This will write an MPS format file to the given file name.  It will use the default\
     1258 directory given by 'directory'.  A name of '$' will use the previous value for the name.  This\
     1259 is initialized to 'default.mps'."
    11961260       ""
    11971261       );
     
    12171281    parameters[numberParameters-1].setLonghelp
    12181282      (
    1219        ""
     1283       "This stops the execution of Clp, end, exit, quit and stop are synonyms"
    12201284       );
    12211285    parameters[numberParameters++]=
     
    12301294    int numberGoodCommands=0;
    12311295    bool * goodModels = new bool[1];
    1232     int getNewMatrix=0;
    12331296   
    12341297   
     
    14261489                models[iModel].setPrimalColumnPivotAlgorithm(steep);
    14271490              } else if (action==4) {
    1428                 ClpPrimalColumnSteepest steep(0);
     1491                ClpPrimalColumnSteepest steep(1);
    14291492                models[iModel].setPrimalColumnPivotAlgorithm(steep);
    14301493              } else if (action==5) {
     
    14341497              break;
    14351498            case SCALING:
    1436               models[iModel].scaling(1-action);
     1499              if (action<2)
     1500                models[iModel].scaling(1-action);
     1501              else
     1502                models[iModel].scaling(action);
    14371503              break;
    14381504            case SPARSEFACTOR:
     
    14631529              break;
    14641530            case CRASH:
    1465               doCrash=-action;
     1531              doCrash=action;
    14661532              break;
    14671533            case MESSAGES:
     
    15381604            break;
    15391605          case PLUSMINUS:
    1540             getNewMatrix=1;
     1606            if (goodModels[iModel]) {
     1607              ClpMatrixBase * saveMatrix = models[iModel].clpMatrix();
     1608              ClpPackedMatrix* clpMatrix =
     1609                dynamic_cast< ClpPackedMatrix*>(saveMatrix);
     1610              if (clpMatrix) {
     1611                ClpPlusMinusOneMatrix * newMatrix = new ClpPlusMinusOneMatrix(*(clpMatrix->matrix()));
     1612                if (newMatrix->getIndices()) {
     1613                  models[iModel].replaceMatrix(newMatrix);
     1614                  delete saveMatrix;
     1615                  std::cout<<"Matrix converted to +- one matrix"<<std::endl;
     1616                } else {
     1617                  std::cout<<"Matrix can not be converted to +- 1 matrix"<<std::endl;
     1618                }
     1619              } else {
     1620                std::cout<<"Matrix not a ClpPackedMatrix"<<std::endl;
     1621              }
     1622            } else {
     1623              std::cout<<"** Current model not valid"<<std::endl;
     1624            }
    15411625            break;
    15421626          case NETWORK:
    1543             getNewMatrix=2;
     1627            if (goodModels[iModel]) {
     1628              ClpMatrixBase * saveMatrix = models[iModel].clpMatrix();
     1629              ClpPackedMatrix* clpMatrix =
     1630                dynamic_cast< ClpPackedMatrix*>(saveMatrix);
     1631              if (clpMatrix) {
     1632                ClpNetworkMatrix * newMatrix = new ClpNetworkMatrix(*(clpMatrix->matrix()));
     1633                if (newMatrix->getIndices()) {
     1634                  models[iModel].replaceMatrix(newMatrix);
     1635                  delete saveMatrix;
     1636                  std::cout<<"Matrix converted to network matrix"<<std::endl;
     1637                } else {
     1638                  std::cout<<"Matrix can not be converted to network matrix"<<std::endl;
     1639                }
     1640              } else {
     1641                std::cout<<"Matrix not a ClpPackedMatrix"<<std::endl;
     1642              }
     1643            } else {
     1644              std::cout<<"** Current model not valid"<<std::endl;
     1645            }
    15441646            break;
    15451647          case IMPORT:
     
    18381940          case ALLSLACK:
    18391941            models[iModel].createStatus();
     1942            {
     1943              // and do solution
     1944              int iColumn;
     1945              double * solution = models[iModel].primalColumnSolution();
     1946              const double * lower = models[iModel].columnLower();
     1947              const double * upper = models[iModel].columnUpper();
     1948              int numberColumns = models[iModel].numberColumns();
     1949              for (iColumn=0;iColumn<numberColumns;iColumn++) {
     1950                if (lower[iColumn]>0.0) {
     1951                  solution[iColumn]=lower[iColumn];
     1952                } else if (upper[iColumn]<0.0) {
     1953                  solution[iColumn]=upper[iColumn];
     1954                } else {
     1955                  solution[iColumn]=0.0;
     1956                }
     1957              }
     1958            }
     1959            break;
     1960          case REVERSE:
     1961            if (goodModels[iModel]) {
     1962              int iColumn;
     1963              int numberColumns=models[iModel].numberColumns();
     1964              double * dualColumnSolution =
     1965                models[iModel].dualColumnSolution();
     1966              ClpObjective * obj = models[iModel].objectiveAsObject();
     1967              assert(dynamic_cast<ClpLinearObjective *> (obj));
     1968              double offset;
     1969              double * objective = obj->gradient(NULL,offset,true);
     1970              for (iColumn=0;iColumn<numberColumns;iColumn++) {
     1971                dualColumnSolution[iColumn] = dualColumnSolution[iColumn];
     1972                objective[iColumn] = -objective[iColumn];
     1973              }
     1974              int iRow;
     1975              int numberRows=models[iModel].numberRows();
     1976              double * dualRowSolution =
     1977                models[iModel].dualRowSolution();
     1978              for (iRow=0;iRow<numberRows;iRow++)
     1979                dualRowSolution[iRow] = dualRowSolution[iRow];
     1980            }
    18401981            break;
    18411982          case DIRECTORY:
Note: See TracChangeset for help on using the changeset viewer.