Changeset 343


Ignore:
Timestamp:
Apr 5, 2004 9:27:19 AM (17 years ago)
Author:
forrest
Message:

dualRanging

Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpSimplex.cpp

    r339 r343  
    845845int ClpSimplex::internalFactorize ( int solveType)
    846846{
    847 
    848847  int iRow,iColumn;
    849848  int totalSlacks=numberRows_;
     
    34353434      if (upperOut_>0.0)
    34363435        dualBound_=2.0*upperOut_;
    3437       returnCode = ((ClpSimplexPrimal *) this)->dual(0);
     3436      returnCode = ((ClpSimplexDual *) this)->dual(0);
    34383437      dualBound_=saveBound;
    34393438    } else {
    3440       returnCode = ((ClpSimplexDual *) this)->primal(0);
     3439      returnCode = ((ClpSimplexPrimal *) this)->primal(0);
    34413440    }
    34423441    setInitialDenseFactorization(denseFactorization);
     
    34463445  }
    34473446  return returnCode;
     3447}
     3448/* Dual ranging.
     3449   This computes increase/decrease in cost for each given variable and corresponding
     3450   sequence numbers which would change basis.  Sequence numbers are 0..numberColumns
     3451   and numberColumns.. for artificials/slacks.
     3452   For non-basic variables the sequence number will be that of the non-basic variables.
     3453   
     3454   Up to user to provide correct length arrays.
     3455   
     3456   Returns non-zero if infeasible unbounded etc
     3457*/
     3458#include "ClpSimplexOther.hpp"
     3459int ClpSimplex::dualRanging(int numberCheck,const int * which,
     3460                            double * costIncrease, int * sequenceIncrease,
     3461                            double * costDecrease, int * sequenceDecrease)
     3462{
     3463  int savePerturbation = perturbation_;
     3464  perturbation_=100;
     3465  int returnCode = ((ClpSimplexPrimal *) this)->primal(0,1);
     3466  if (problemStatus_==10) {
     3467    //printf("Cleaning up with dual\n");
     3468    bool denseFactorization = initialDenseFactorization();
     3469    // It will be safe to allow dense
     3470    setInitialDenseFactorization(true);
     3471    // check which algorithms allowed
     3472    int dummy;
     3473    if ((matrix_->generalExpanded(this,4,dummy)&2)!=0) {
     3474      // upperOut_ has largest away from bound
     3475      double saveBound=dualBound_;
     3476      if (upperOut_>0.0)
     3477        dualBound_=2.0*upperOut_;
     3478      returnCode = ((ClpSimplexDual *) this)->dual(0,1);
     3479      dualBound_=saveBound;
     3480    } else {
     3481      returnCode = ((ClpSimplexPrimal *) this)->primal(0,1);
     3482    }
     3483    setInitialDenseFactorization(denseFactorization);
     3484    if (problemStatus_==10)
     3485      problemStatus_=0;
     3486  }
     3487  perturbation_=savePerturbation;
     3488  if (problemStatus_) {
     3489    finish(); // get rid of arrays
     3490    return 1; // odd status
     3491  }
     3492  ((ClpSimplexOther *) this)->dualRanging(numberCheck,which,
     3493                                          costIncrease,sequenceIncrease,
     3494                                          costDecrease,sequenceDecrease);
     3495  finish(); // get rid of arrays
     3496  return 0;
    34483497}
    34493498#include "ClpSimplexPrimalQuadratic.hpp"
  • trunk/ClpSimplexDual.cpp

    r336 r343  
    107107//#define CLP_DEBUG 1
    108108// dual
    109 int ClpSimplexDual::dual (int ifValuesPass )
     109int ClpSimplexDual::dual (int ifValuesPass , int startFinishOptions)
    110110{
    111111
     
    382382
    383383  // clean up
    384   finish();
     384  if (!startFinishOptions)
     385    finish();
    385386  delete [] saveDuals;
    386387
  • trunk/ClpSimplexPrimal.cpp

    r336 r343  
    9595#include <iostream>
    9696// primal
    97 int ClpSimplexPrimal::primal (int ifValuesPass )
     97int ClpSimplexPrimal::primal (int ifValuesPass , int startFinishOptions)
    9898{
    9999
     
    402402  // clean up
    403403  unflag();
    404   finish();
     404  if (!startFinishOptions)
     405    finish();
    405406  restoreData(data);
    406407  return problemStatus_;
  • trunk/Makefile.Clp

    r280 r343  
    3333LIBSRC += ClpSimplex.cpp
    3434LIBSRC += ClpSimplexDual.cpp
     35LIBSRC += ClpSimplexOther.cpp
    3536LIBSRC += ClpSimplexPrimal.cpp
    3637LIBSRC += ClpSimplexPrimalQuadratic.cpp
  • trunk/Samples/Makefile

    r288 r343  
    3434IncDir += ${readlineIncDir}
    3535IncDir += ${lapackIncDir}
     36IncDir += ${taucsIncDir}
    3637
    3738LibDir :=
     
    4243LibDir += ${readlineLibDir}
    4344LibDir += ${lapackLibDir}
     45#LibDir += ${taucsLibDir}
    4446
    4547LibName :=
     
    5052LibName += ${readlineLibName}
    5153LibName += ${lapackLibName}
     54#LibName += ${taucsLibName}
    5255
    5356Define :=
     
    5861Define += ${readlineDefine}
    5962Define += ${lapackDefine}
     63Define += ${taucsDefine}
    6064
    6165CXXFLAGS += $(OPTFLAG)
     
    8488
    8589#LDFLAGS += -lefence
     90#LDFLAGS += -Wl,-static
    8691#LDFLAGS += -lwsmpP4 -lpthread
    87 #OSL_LIB_DIR = /home/forrest/osl/lib
    88 #LDFLAGS += -L $(OSL_LIB_DIR) -Wl,-rpath,$(OSL_LIB_DIR) -losl-g-nolic-native-32
     92OSL_LIB_DIR = /home/forrest/osl/lib
     93LDFLAGS += -L $(OSL_LIB_DIR) -Wl,-rpath,$(OSL_LIB_DIR) -losl-O-nolic-native-32
     94#LDFLAGS += -pg
    8995###############################################################################
    9096
  • trunk/Samples/decompose.cpp

    r336 r343  
    4242  } else if (numberRows==5418) {
    4343    for (iRow=564;iRow<603;iRow++)
     44      rowBlock[iRow]=-1;
     45  } else if (numberRows==10280) {
     46    // osa-60
     47    for (iRow=10198;iRow<10280;iRow++)
    4448      rowBlock[iRow]=-1;
    4549  } else if (numberRows==1503) {
     
    117121  }
    118122  printf("%d blocks found\n",numberBlocks);
     123  if (numberBlocks>50) {
     124    int iBlock;
     125    for (iRow=0;iRow<numberRows;iRow++) {
     126      iBlock = rowBlock[iRow];
     127      if (iBlock>=0)
     128        rowBlock[iRow] = iBlock%50;
     129    }
     130    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     131      iBlock = columnBlock[iColumn];
     132      if (iBlock>=0)
     133        columnBlock[iColumn] = iBlock%50;
     134    }
     135    numberBlocks=50;
     136  }
    119137  delete [] stack;
    120138  // make up problems
  • trunk/Samples/testGub.cpp

    r336 r343  
    184184          doUpper=true;
    185185      }
     186    }
     187    if (!numberNormal) {
     188      printf("Putting back one gub row to make non-empty\n");
     189      for (iColumn=gubStart[putGub];iColumn< gubEnd[putGub];iColumn++)
     190        mark[numberNormal++]=iColumn;
     191      putGub++;
     192      numberGub--;
    186193    }
    187194    ClpSimplex model2(&model,numberNonGub,which+putNonGub,numberNormal,mark);
  • trunk/Samples/testGub2.cpp

    r311 r343  
    152152          doUpper=true;
    153153      }
     154    }
     155    if (!numberNormal) {
     156      printf("Putting back one gub row to make non-empty\n");
     157      for (iColumn=gubStart[putGub];iColumn< gubEnd[putGub];iColumn++)
     158        mark[numberNormal++]=iColumn;
     159      putGub++;
     160      numberGub--;
    154161    }
    155162    ClpSimplex model2(&model,numberNonGub,which+putNonGub,numberNormal,mark);
  • trunk/Test/ClpMain.cpp

    r342 r343  
    5959
    6060  LOGLEVEL=101,MAXFACTOR,PERTVALUE,MAXITERATION,PRESOLVEPASS,IDIOT,SPRINT,
     61  OUTPUTFORMAT,
    6162 
    6263  DIRECTION=201,DUALPIVOT,SCALING,ERRORSALLOWED,KEEPNAMES,SPARSEFACTOR,
     
    870871    int keepImportNames=1;
    871872    int doIdiot=-1;
     873    int outputFormat=2;
    872874    int doCrash=0;
    873875    int doSprint=-1;
     
    11581160       );
    11591161    parameters[numberParameters-1].setDoubleValue(1.0);
     1162    parameters[numberParameters++]=
     1163      ClpItem("output!Format","Which output format to use",
     1164              1,6,OUTPUTFORMAT);
     1165    parameters[numberParameters-1].setLonghelp
     1166      (
     1167       "Normally export will be done using normal representation for numbers and two values\
     1168 per line.  You may want to do just one per line (for grep or suchlike) and you may wish\
     1169 to save with absolute accuracy using a coded version of the IEEE value. A value of 2 is normal.\
     1170 otherwise odd values gives one value per line, even two.  Values 1,2 give normal format, 3,4\
     1171 gives greater precision, while 5,6 give IEEE values."
     1172       );
     1173    parameters[numberParameters-1].setIntValue(outputFormat);
    11601174    parameters[numberParameters++]=
    11611175      ClpItem("passP!resolve","How many passes in presolve",
     
    15021516            else if (parameters[iParam].type()==SPRINT)
    15031517              doSprint = value;
     1518            else if (parameters[iParam].type()==OUTPUTFORMAT)
     1519              outputFormat = value;
    15041520            else
    15051521              parameters[iParam].setIntParameter(models+iModel,value);
     
    18971913                }
    18981914#else
    1899                 model2->writeMps(fileName.c_str(),2,2);
     1915                model2->writeMps(fileName.c_str(),(outputFormat-1)/2,1+((outputFormat-1)&1));
    19001916#endif
    19011917                if (deleteModel2)
  • trunk/Test/unitTest.cpp

    r317 r343  
    543543    }
    544544  }
     545  // Test dual ranging
     546  {   
     547    CoinMpsIO m;
     548    std::string fn = mpsDir+"exmip1";
     549    m.readMps(fn.c_str(),"mps");
     550    ClpSimplex model;
     551    model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
     552                         m.getObjCoefficients(),
     553                         m.getRowLower(),m.getRowUpper());
     554    model.primal();
     555    int which[8] = {0,1,2,3,4,5,6,7};
     556    double costIncrease[8];
     557    int sequenceIncrease[8];
     558    double costDecrease[8];
     559    int sequenceDecrease[8];
     560    // ranging
     561    model.dualRanging(8,which,costIncrease,sequenceIncrease,
     562                      costDecrease,sequenceDecrease);
     563    for (int i=0;i<8;i++)
     564      printf("%d increase %g %d, decrease %g %d\n",
     565             i,costIncrease[i],sequenceIncrease[i],
     566             costDecrease[i],sequenceDecrease[i]);
     567    assert (fabs(costDecrease[3])<1.0e-4);
     568    assert (fabs(costIncrease[7]-1.0)<1.0e-4);
     569    model.setOptimizationDirection(-1);
     570    {
     571      int j;
     572      double * obj = model.objective();
     573      int n=model.numberColumns();
     574      for (j=0;j<n;j++)
     575        obj[j] *= -1.0;
     576    }
     577    double costIncrease2[8];
     578    int sequenceIncrease2[8];
     579    double costDecrease2[8];
     580    int sequenceDecrease2[8];
     581    // ranging
     582    model.dualRanging(8,which,costIncrease2,sequenceIncrease2,
     583                      costDecrease2,sequenceDecrease2);
     584    for (int i=0;i<8;i++) {
     585      assert (fabs(costIncrease[i]-costDecrease2[i])<1.0e-6);
     586      assert (fabs(costDecrease[i]-costIncrease2[i])<1.0e-6);
     587      assert (sequenceIncrease[i]==sequenceDecrease2[i]);
     588      assert (sequenceDecrease[i]==sequenceIncrease2[i]);
     589    }
     590  }
    545591  // test steepest edge
    546592  {   
  • trunk/include/ClpSimplex.hpp

    r336 r343  
    176176  /// Solves quadratic using Dantzig's algorithm - primal
    177177  int quadraticPrimal(int phase=2);
     178  /** Dual ranging.
     179      This computes increase/decrease in cost for each given variable and corresponding
     180      sequence numbers which would change basis.  Sequence numbers are 0..numberColumns
     181      and numberColumns.. for artificials/slacks.
     182      For non-basic variables the sequence number will be that of the non-basic variables.
     183      The increase/decrease value is always >= 0.0
     184
     185      Up to user to provide correct length arrays.
     186
     187      Returns non-zero if infeasible unbounded etc
     188  */
     189  int dualRanging(int numberCheck,const int * which,
     190                  double * costIncrease, int * sequenceIncrease,
     191                  double * costDecrease, int * sequenceDecrease);
    178192  /// Passes in factorization
    179193  void setFactorization( ClpFactorization & factorization);
  • trunk/include/ClpSimplexDual.hpp

    r225 r343  
    114114  */
    115115
    116   int dual(int ifValuesPass);
     116  int dual(int ifValuesPass,int startFinishOptions=0);
    117117  /** For strong branching.  On input lower and upper are new bounds
    118118      while on output they are change in objective function values
  • trunk/include/ClpSimplexPrimal.hpp

    r320 r343  
    111111  */
    112112
    113   int primal(int ifValuesPass=0);
     113  int primal(int ifValuesPass=0, int startFinishOptions=0);
    114114  //@}
    115115
Note: See TracChangeset for help on using the changeset viewer.