Ignore:
Timestamp:
Oct 9, 2003 12:12:15 PM (16 years ago)
Author:
forrest
Message:

Start of mini sprint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pre/Samples/driver.cpp

    r180 r222  
    1 // Copyright (C) 2002, International Business Machines
     1// Copyright (C) 2002,2003 International Business Machines
    22// Corporation and others.  All Rights Reserved.
    33
     
    55#include "ClpPresolve.hpp"
    66#include "CoinHelperFunctions.hpp"
     7#include "CoinTime.hpp"
    78#include "ClpDualRowSteepest.hpp"
    89#include "ClpPrimalColumnSteepest.hpp"
     
    2627
    2728  double time1 = CoinCpuTime();
    28   /*
    29     This driver show how to do presolve.
    30   */
    31   ClpSimplex * model2;
    32   ClpPresolve pinfo;
    33   int numberPasses=5; // can change this
    34   /* Use a tolerance of 1.0e-8 for feasibility, treat problem as
    35      not being integer, do "numberpasses" passes and throw away names
    36      in presolved model */
    37   model2 = pinfo.presolvedModel(model,1.0e-8,false,numberPasses,false);
    38   if (!model2) {
    39     fprintf(stderr,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    40             argv[1],1.0e-8);
    41     fprintf(stdout,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    42             argv[1],1.0e-8);
    43     // model was infeasible - maybe try again with looser tolerances
    44     model2 = pinfo.presolvedModel(model,1.0e-7,false,numberPasses,false);
    45     if (!model2) {
    46       fprintf(stderr,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    47               argv[1],1.0e-7);
    48       fprintf(stdout,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    49               argv[1],1.0e-7);
    50       exit(2);
    51     }
    52   }
    53   // change factorization frequency from 200
    54   model2->setFactorizationFrequency(100+model2->numberRows()/50);
    5529  if (argc<3 ||!strstr(argv[2],"primal")) {
    5630    // Use the dual algorithm unless user said "primal"
    57     /* faster if bounds tightened as then dual can flip variables
    58         to other bound to stay dual feasible.  We can trash the bounds as
    59         this model is going to be thrown away
    60     */
    61     int numberInfeasibilities = model2->tightenPrimalBounds();
    62     if (numberInfeasibilities)
    63       std::cout<<"** Analysis indicates model infeasible"
    64                <<std::endl;
    65     model2->crash(1000.0,2);
    66     ClpDualRowSteepest steep(1);
    67     model2->setDualRowPivotAlgorithm(steep);
    68     model2->dual();
     31    model.initialDualSolve();
    6932  } else {
    70     ClpPrimalColumnSteepest steep(1);
    71     model2->setPrimalColumnPivotAlgorithm(steep);
    72     model2->primal();
     33    model.initialPrimalSolve();
    7334  }
    74   pinfo.postsolve(true);
    75 
    76   int numberIterations=model2->numberIterations();;
    77   delete model2;
    78   /* After this postsolve model should be optimal.
    79      We can use checkSolution and test feasibility */
    80   model.checkSolution();
    81   if (model.numberDualInfeasibilities()||
    82       model.numberPrimalInfeasibilities())
    83     printf("%g dual %g(%d) Primal %g(%d)\n",
    84            model.objectiveValue(),
    85            model.sumDualInfeasibilities(),
    86            model.numberDualInfeasibilities(),
    87            model.sumPrimalInfeasibilities(),
    88            model.numberPrimalInfeasibilities());
    89   // But resolve for safety
    90   model.primal(1);
    91 
    92   numberIterations += model.numberIterations();;
    9335  // for running timing tests
    9436  std::cout<<argv[1]<<" Objective "<<model.objectiveValue()<<" took "<<
    95     numberIterations<<" iterations and "<<
     37    model.numberIterations()<<" iterations and "<<
    9638    CoinCpuTime()-time1<<" seconds"<<std::endl;
    97 
     39 
    9840  std::string modelName;
    9941  model.getStrParam(ClpProbName,modelName);
Note: See TracChangeset for help on using the changeset viewer.