Example #1
0
int main(int argc, char **argv)
{
   OsiSymSolverInterface si;

   si.loadProblem(argc, argv);

   si.setSymDblParam(OsiSymGranularity, 0.999999);

   si.branchAndBound();
   
   return(0);
}
Example #2
0
int main(int argc, char **argv)
{

  OsiSymSolverInterface si;
  si.parseCommandLine(argc, argv);
  si.loadProblem();

  si.setObj2Coeff(1, 1);

  si.multiCriteriaBranchAndBound();

  return(0);

}
Example #3
0
int main(int argc, char **argv)
{
   OsiSymSolverInterface si;

   /* Parse the command line */
   si.parseCommandLine(argc, argv);
   
   /* Read in the problem */
   si.loadProblem();

   /* Find a priori problem bounds */
   si.findInitialBounds();

   /* Solve the problem */
   si.branchAndBound();
   
   return(0);
}
Example #4
0
int main(int argc, char **argv)
{

   /* Create an OsiSym object */
   OsiSymSolverInterface si;

   /* Parse the command line */
   si.parseCommandLine(argc, argv);
   
   /* Read in the problem */
   si.loadProblem();

   si.setSymParam(OsiSymGapLimit,.05);

   /* Solve the problem */
   si.initialSolve();

   return(0);
}
Example #5
0
int main(int argc, char **argv)
{

  OsiSymSolverInterface si;
  si.parseCommandLine(argc, argv);
  si.loadProblem();
  si.setSymParam(OsiSymKeepWarmStart, true);
  si.setSymParam(OsiSymFindFirstFeasible, true);
   /* set node selection rule to DEPTH_FIRST_SEARCH */
  si.setSymParam(OsiSymSearchStrategy, 3);

  si.initialSolve();

  si.setSymParam(OsiSymFindFirstFeasible, false);
   /* set node selection rule to BEST_FIRST_SEARCH */
  si.setSymParam(OsiSymSearchStrategy, 4);

  si.resolve();
  
  return(0);

}
Example #6
0
int main(int argc, char **argv)
{
   OsiSymSolverInterface si;

   //si.setSymParam(OsiSymVerbosity, 3);
   si.setSymParam(OsiSymGranularity, 0.9999); 
   si.setSymParam("generate_cgl_cuts", FALSE);
   si.setSymParam("lp_executable_name", "vrp_lp_cg");
   si.setSymParam("cp_executable_name", "vrp_cp");
   
   /* Parse the command line */
   si.parseCommandLine(argc, argv);
   
   /* Read in the problem */
   si.loadProblem();

   /* Find a priori problem bounds */
   si.findInitialBounds();
   
   /* Solve the problem */
   si.branchAndBound();

   return(0);
}
Example #7
0
int main(int argc, char **argv)
{

  OsiSymSolverInterface si;
  si.parseCommandLine(argc, argv);
  si.loadProblem();

  si.setSymParam(OsiSymSensitivityAnalysis, true);

  si.initialSolve();

  int ind[2];
  double val[2];
  ind[0] = 4; val[0] = 7000;
  ind[1] = 7; val[1] = 6000;
  
  double lb = si.getLbForNewRhs(2, ind, val);
  double ub =  si.getUbForNewRhs(2, ind, val);

  printf("\nBounds for the new rhs:\n lb: %f\n ub: %f \n\n", lb, ub);

  return(0);

}
Example #8
0
int main(int argc, char **argv)
{
   int i;
   problem *env;
   double gamma, gamma0, gamma1, tau, slope;
   double start_time;

   solution_data utopia1;
   solution_data utopia2;
   solution_data solutions[MAX_NUM_PAIRS];
   int numsolutions = 0, numprobs = 0, numinfeasible = 0;
   solution_pairs pairs[MAX_NUM_PAIRS];
   int numpairs = 0, cur_position = 0, first = 0, last = 0, previous = 0;
   double *indices, *values;
   int length;
   int solution1, solution2;
   double utopia[2];
   node_desc *root= NULL;
   base_desc *base = NULL;
   double compare_sol_tol, ub = 0.0;
   
   start_time = wall_clock(NULL);

   /* Initialize the SYMPHONY environment */
   OsiSymSolverInterface si;
   
   /* Get pointer to the SYMPHONY environment */
   env = si.getSymphonyEnvironment();

   /* Parse the command line */
   si.parseCommandLine(argc, argv);
   
   /* Read in the problem */
   si.loadProblem();

   /* Find a priori problem bounds */
   si.findInitialBounds();
   
   /* Set some parameters */
   compare_sol_tol = p->par.compare_solution_tolerance;
   si.setSymParam(OsiSymGranularity,-MAX(p->lp_par.rho, compare_sol_tol));

#ifdef BINARY_SEARCH
   printf("Using binary search with tolerance = %f...\n",
	  p->par.binary_search_tolerance);
#endif
#ifdef LIFO
   printf("Using LIFO search order...\n");
#endif
   if (p->lp_par.rho > 0){
      printf("Using secondary objective weight %.8f\n", cnrp->lp_par.rho);
   }
   printf("\n");

#ifdef SAVE_CUT_POOL
   printf("Saving the global cut pool between iterations...\n");
   si.createPermanentCutPools();
   si.setSymParam(OsiSymUsePermanentCutPools, TRUE);
#endif
   
   /* First, calculate the utopia point */
   p->lp_par.gamma = 1.0;
   p->lp_par.tau = 0.0;
      
   printf("***************************************************\n");
   printf("***************************************************\n");
   printf("Now solving with gamma = 1.0 tau = 0.0 \n", gamma, tau);  
   printf("***************************************************\n");
   printf("***************************************************\n\n");

   /* Solve */
   si.branchAndBound();
   numprobs++;
   
   /* Store the solution */
   length = solutions[numsolutions].length = p->best_sol.xlength;
   indices = solutions[numsolutions].indices = (int *) calloc(length, ISIZE);
   values = solutions[numsolutions].values = (double *) calloc(length, DSIZE);
   memcpy((char *) indices, p->bestsol.xind, length * ISIZE);
   memcpy((char *) values, p->bestsol.xval, length * DSIZE);
   solutions[numsolutions].gamma = 1.0;
   solutions[numsolutions].tau = 0.0;
   solutions[numsolutions].obj[0] = p->obj[0];
   solutions[numsolutions++].obj[1] = p->obj[1];
   utopia[0] = p->obj[0];
      
   cnrp->lp_par.gamma = 0.0;
   cnrp->cg_par.tau = cnrp->lp_par.tau = 1.0;
      
   printf("***************************************************\n");
   printf("***************************************************\n");
   printf("Now solving with gamma = 0.0 tau = 1.0 \n", gamma, tau);  
   printf("***************************************************\n");
   printf("***************************************************\n\n");

   /* Solve */
   si.branchAndBound();
   numprobs++;
   
   /* Store the solution */
   length = solutions[numsolutions].length = p->best_sol.xlength;
   indices = solutions[numsolutions].indices = (int *) calloc(length, ISIZE);
   values = solutions[numsolutions].values = (double *) calloc(length, DSIZE);
   memcpy((char *) indices, p->bestsol.xind, length * ISIZE);
   memcpy((char *) values, p->bestsol.xval, length * DSIZE);
   solutions[numsolutions].gamma = 0.0;
   solutions[numsolutions].tau = 1.0;
   solutions[numsolutions].obj[0] = p->obj[0];
   solutions[numsolutions++].obj[1] = p->obj[1];
   utopia[1] = p->obj[1];
   
   p->utopia[1] = utopia[1];
   p->utopia[0] = utopia[0];
   
   printf("***************************************************\n");
   printf("***************************************************\n");
   printf("Utopia point has fixed cost %.3f and variable cost %.3f \n",
	  utopia[0], utopia[1]);
   printf("***************************************************\n");
   printf("***************************************************\n\n");
   
   /* Add the first pair to the list */
#ifdef BINARY_SEARCH
   pairs[first].gamma1 = 1.0;
   pairs[first].gamma2 = 0.0;
#endif
   pairs[first].solution1 = 0;
   pairs[first].solution2 = 1;

   first = last = 0;
   numpairs = 1;

   /* Keep taking pairs off the list and processing them until there are none
      left */
   while (numpairs > 0 && numpairs < MAX_NUM_PAIRS &&
	  numsolutions < MAX_NUM_SOLUTIONS &&
	  numinfeasible < MAX_NUM_INFEASIBLE){

#ifdef LIFO
      solution1 = pairs[last].solution1;
      solution2 = pairs[last].solution2;
      cur_position = last;
      if (--last < 0){
	 last = MAX_NUM_PAIRS - 1;
      }
      numpairs--;
#else
      solution1 = pairs[first].solution1;
      solution2 = pairs[first].solution2;
      cur_position = first;
      if (++first > MAX_NUM_PAIRS-1)
	 first = 0;
      numpairs--;
#endif

#ifdef BINARY_SEARCH
      gamma = (pairs[cur_position].gamma1 + pairs[cur_position].gamma2)/2;
#elif defined(FIND_NONDOMINATED_SOLUTIONS)
      gamma = (utopia[1] - solutions[solution1].obj[1])/
	 (utopia[0] - solutions[solution2].obj[0] +
	  utopia[1] - solutions[solution1].obj[1]);
#else
      slope = (solutions[solution1].obj[1] -
	       solutions[solution2].obj[1])/
	      (solutions[solution2].obj[0] -
	       solutions[solution1].obj[0]);
      gamma = slope/(1+slope);
#endif
      tau = 1 - gamma;
      
      p->lp_par.gamma = gamma;
      p->lp_par.tau = tau;

      /* Find upper bound */

      env->has_ub = FALSE;
      env->ub = MAXDOUBLE;
#ifndef BINARY_SEARCH
      for (i = 0; i < numsolutions; i++){
#ifdef FIND_NONDOMINATED_SOLUTIONS
	 ub = MAX(gamma*(solutions[i].obj[0] - utopia[0]),
		  tau*(solutions[i].obj[1] - utopia[1]));
#else
	 ub = gamma*solutions[i].obj[0] + tau*solutions[i].obj[1];
#endif 
	 if (ub < env->ub){
	    env->has_ub = TRUE;
	    env->ub = ub - compare_sol_tol;
	 }
      }
#endif
      
      printf("***************************************************\n");
      printf("***************************************************\n");
      printf("Now solving with gamma = %.6f tau = %.6f \n", gamma, tau);  
      printf("***************************************************\n");
      printf("***************************************************\n\n");
      
      p->obj[0] = p->obj[1] = 0.0;
      
      si.branchAndBound();
      numprobs++;
      
#ifdef BINARY_SEARCH
      if (p->obj[0] - solutions[solution1].obj[0] <
	  compare_sol_tol &&
	  solutions[solution1].obj[1] - p->obj[1] <
	  compare_sol_tol){
	 if (pairs[cur_position].gamma1 - gamma >
	     cnrp->par.binary_search_tolerance){
	    if (++last > MAX_NUM_PAIRS - 1)
	       last = 0;
	    pairs[last].solution1 = solution1;
	    pairs[last].solution2 = solution2;
	    pairs[last].gamma1 = gamma;
	    pairs[last].gamma2 = pairs[cur_position].gamma2;
	    numpairs++;
	 }
	 continue;
      }
      if (solutions[solution2].obj[0] - p->obj[0] < compare_sol_tol
	  && p->obj[1] - solutions[solution2].obj[1] <
	  compare_sol_tol){
	 if (gamma - pairs[cur_position].gamma2 >
	     cnrp->par.binary_search_tolerance){
	    if (++last > MAX_NUM_PAIRS - 1)
	       last = 0;
	    pairs[last].solution1 = solution1;
	    pairs[last].solution2 = solution2;
	    pairs[last].gamma1 = pairs[cur_position].gamma1;
	    pairs[last].gamma2 = gamma;
	    numpairs++;
	 }
	 continue;
      }
#else
      if (p->obj[0] == 0.0 && p->obj[1] == 0.0){
	 numinfeasible++;
	 continue;
      }else if (p->obj[0] - solutions[solution1].obj[0] <
		compare_sol_tol &&
		solutions[solution1].obj[1] - p->obj[1] <
		compare_sol_tol){
	 numinfeasible++;
	 continue;
      }else if (solutions[solution2].obj[0] - p->obj[0] <
		compare_sol_tol &&
		p->obj[1] - solutions[solution2].obj[1] <
		compare_sol_tol){
	 numinfeasible++;
	 continue;
      }
#endif
      
      /* Insert new solution */
      numinfeasible = 0;
      if (last + 2 == MAX_NUM_PAIRS){
	 last = 0;
	 previous = MAX_NUM_PAIRS - 1;
      }else if (last + 2 == MAX_NUM_PAIRS + 1){
	 last = 1;
	 previous = 0;
      }else{
	 last += 2;
	 previous = last - 1;
      }
#ifdef BINARY_SEARCH
      pairs[previous].gamma1 = pairs[cur_position].gamma1;
      pairs[previous].gamma2 = gamma;
      pairs[last].gamma1 = gamma;
      pairs[last].gamma2 = pairs[cur_position].gamma2;
#endif
      pairs[previous].solution1 = solution1;
      pairs[previous].solution2 = solution2;
      pairs[last].solution1 = solution2;
      pairs[last].solution2 = solution2+1;
      numpairs += 2;
      for (i = numsolutions; i > solution2; i--){
	 solutions[i] = solutions[i-1];
      }
      numsolutions++;
#ifndef LIFO
      if (first < last){
	 for (i = first; i < last - 1; i++){
	    if (pairs[i].solution1 >= solution2){
	       pairs[i].solution1++;
	    }
	    if (pairs[i].solution2 >= solution2){
	       pairs[i].solution2++;
	    }
	 }
      }else{
	 for (i = first; i < MAX_NUM_PAIRS - (last == 0 ? 1 : 0); i++){
	    if (pairs[i].solution1 >= solution2){
	       pairs[i].solution1++;
	    }
	    if (pairs[i].solution2 >= solution2){
	       pairs[i].solution2++;
	    }
	 }
	 for (i = 0; i < last - 1; i++){
	    if (pairs[i].solution1 >= solution2){
	       pairs[i].solution1++;
	    }
	    if (pairs[i].solution2 >= solution2){
	       pairs[i].solution2++;
	    }
	 }
      }
	 
#endif
      length = solutions[solutions2].length = p->best_sol.xlength;
      indices = solutions[solutions2].indices = (int *) calloc(length, ISIZE);
      values = solutions[solutions2].values = (double *) calloc(length, DSIZE);
      memcpy((char *) indices, p->bestsol.xind, length * ISIZE);
      memcpy((char *) values, p->bestsol.xval, length * DSIZE);
      solutions[solution2].gamma = gamma;
      solutions[solution2].tau = tau;
      solutions[solution2].obj[0] = p->obj[0];
      solutions[solution2].obj[1] = p->obj[1];
   }

   printf("\n********************************************************\n");

   if (numsolutions >= MAX_NUM_SOLUTIONS){
      printf("Maximum number of solutions (%i) reached\n\n",
	     MAX_NUM_SOLUTIONS);
   }

   if (numinfeasible >= MAX_NUM_INFEASIBLE){
      printf("Maximum number of infeasible subproblems (%i) reached\n\n",
	     MAX_NUM_INFEASIBLE);
   }
   
   if (numpairs >= MAX_NUM_PAIRS){
      printf("Maximum number of solution pairs (%i) reached\n\n",
	     MAX_NUM_PAIRS);
      printf("\n********************************************************\n");
#ifdef FIND_NONDOMINATED_SOLUTIONS
      printf(  "* Found set of non-dominated solutions!!!!!!! *\n");
#else
      printf(  "* Found set of supported solutions!!!!!!!     *\n");
#endif
   }else{
      printf("\n********************************************************\n");
#ifdef FIND_NONDOMINATED_SOLUTIONS
      printf(  "* Found complete set of non-dominated solutions!!!!!!! *\n");
#else
      printf(  "* Found complete set of supported solutions!!!!!!!     *\n");
#endif
   }
   printf(  "* Now displaying stats...                              *\n");
   printf(  "********************************************************\n\n");

#ifdef SAVE_CUT_POOL
   for (i = 0; i < env->par.tm_par.max_cp_num; i++){
      env->comp_times.bc_time.cut_pool += env->cp[i]->cut_pool_time;
      env->warm_start->stat.cuts_in_pool += env->cp[i]->cut_num;
   }
#endif
   
   print_statistics(&(env->comp_times.bc_time), &(env->warm_start->stat), 0.0,
		    0.0, 0, start_time);

   printf("\nNumber of subproblems solved: %i\n", numprobs);
   printf("Number of solutions found: %i\n\n", numsolutions);
   
   printf("***************************************************\n");
   printf("***************************************************\n");
#ifdef FIND_NONDOMINATED_SOLUTIONS
   printf("Displaying non-dominated solution values and breakpoints\n");  
#else
   printf("Displaying supported solution values and breakpoints\n");  
#endif
   printf("***************************************************\n");
   printf("***************************************************\n\n");

   gamma0 = 1.0;
   for (i = 0; i < numsolutions - 1; i++){
#ifdef FIND_NONDOMINATED_SOLUTIONS
      gamma1 = (utopia[1] - solutions[i].obj[1])/
	 (utopia[0] - solutions[i+1].obj[0] +
	  utopia[1] - solutions[i].obj[1]);
#else
      slope = (solutions[i].obj[1] -
	       solutions[i+1].obj[1])/
	      (solutions[i+1].obj[0] -
	       solutions[i].obj[0]);
      gamma1 = slope/(1+slope);
#endif
      printf("First Objective: %.3f Second Objective: %.3f ",
	     solutions[i].obj[0], solutions[i].obj[1]);
      printf("Range: %.6f - %.6f\n", gamma1, gamma0);
      gamma0 = gamma1;
   }
   printf("First Objective: %.3f Second Objective: %.3f ",
	  solutions[i].obj[0], solutions[i].obj[1]);
   printf("Range: %.6f - %.6f\n", 0.0, gamma0);
   
   for (i = 0 ; i < numsolutions; i++){
      FREE(solutions[i].values);
      FREE(solutions[i].indices);
   }
   
   return(0);
}   
Example #9
0
int main (int argc, const char *argv[])
{
#ifdef _OPENMP
   omp_set_dynamic(FALSE);
   omp_set_num_threads(1);
#endif

  std::string miplib3Dir;
  /*
    Start off with various bits of initialisation that don't really belong
    anywhere else.

    Synchronise C++ stream i/o with C stdio. This makes debugging
    output a bit more comprehensible. It still suffers from interleave of cout
    (stdout) and cerr (stderr), but -nobuf deals with that.
  */
  std::ios::sync_with_stdio() ;
  /*
    Suppress an popup window that Windows shows in response to a crash. See
    note at head of file.
  */
  WindowsErrorPopupBlocker();

#ifdef COIN_HAS_OSITESTS
  /*
    Process command line parameters.
  */
  std::map<std::string,std::string> parms;
  if (processParameters(argc,argv,parms) == false)
  { return 1; }

  std::string mpsDir = parms["-mpsDir"] ;
  std::string netlibDir = parms["-netlibDir"] ;
  miplib3Dir = parms["-miplib3Dir"];

  /*
    Test Osi{Row,Col}Cut routines.
   */
  {
    OsiSymSolverInterface symSi;
    symSi.setSymParam(OsiSymVerbosity, -1);
    testingMessage( "Now testing the OsiRowCut class with OsiSymSolverInterface\n\n");
    OSIUNITTEST_CATCH_ERROR(OsiRowCutUnitTest(&symSi,mpsDir), {}, "symphony", "rowcut unittest");
  }
  {
    OsiSymSolverInterface symSi;
    symSi.setSymParam(OsiSymVerbosity, -1);
    testingMessage( "Now testing the OsiColCut class with OsiSymSolverInterface\n\n" );
    OSIUNITTEST_CATCH_ERROR(OsiColCutUnitTest(&symSi,mpsDir), {}, "symphony", "colcut unittest");
  }
  {
    OsiSymSolverInterface symSi;
    symSi.setSymParam(OsiSymVerbosity, -1);
    testingMessage( "Now testing the OsiRowCutDebugger class with OsiSymSolverInterface\n\n" );
    OSIUNITTEST_CATCH_ERROR(OsiRowCutDebuggerUnitTest(&symSi,mpsDir), {}, "symphony", "rowcut debugger unittest");
  }

  /*
    Run the OsiSym class test. This will also call OsiSolverInterfaceCommonUnitTest.
   */
  testingMessage( "Now testing OsiSymSolverInterface\n\n" );
  OSIUNITTEST_CATCH_ERROR(OsiSymSolverInterfaceUnitTest(mpsDir,netlibDir), {}, "symphony", "Osi unittest");

  /*
    We have run the specialised unit test.
    Check now to see if we need to run through the Netlib problems.
   */
  if (parms.find("-testOsiSolverInterface") != parms.end())
  {
    // Create vector of solver interfaces
    OsiSymSolverInterface* symSi = new OsiSymSolverInterface();
    symSi->setSymParam(OsiSymVerbosity, -1);
    std::vector<OsiSolverInterface*> vecSi(1, symSi);

    testingMessage( "Testing OsiSolverInterface on Netlib problems.\n" );
    OSIUNITTEST_CATCH_ERROR(OsiSolverInterfaceMpsUnitTest(vecSi,netlibDir), {}, "symphony", "Netlib unittest");

    delete vecSi[0];
  }
  else
  {
    testingMessage( "***Skipped Testing of OsiSymSolverInterface on Netlib problems, use -testOsiSolverInterface to run them.***\n" );
  }
#else
  /* a very light version of "parameter processing": check if user call with -miplib3Dir=<dir> */
  if( argc >= 2 && strncmp(argv[1], "-miplib3Dir", 11) == 0 )
    miplib3Dir = argv[1]+12;
#endif

  if (miplib3Dir.length() > 0) {
    int test_status;
    int symargc;
    char* symargv[7];
    testingMessage( "Testing MIPLIB files\n" );

    sym_environment *env = sym_open_environment();
    /* assemble arguments for symphony: -T miplibdir, and -p 2 if we run the punittest */
    symargc = 5;
    symargv[0] = CoinStrdup(argv[0]);
    symargv[1] = "-T";
    symargv[2] = CoinStrdup(miplib3Dir.c_str());
    if( argv[0][0] == 'p' || argv[0][0] == 'P' ) {
       symargv[3] = "-p";
       symargv[4] = "2";
    }else{
       symargv[3] = "-p";
       symargv[4] = "0";
    }
    //sym_parse_command_line(env, symargc, const_cast<char**>(symargv));
    sym_set_int_param(env, "verbosity", -10);
    sym_test(env, symargc, symargv, &test_status);

#ifdef COIN_HAS_OSITESTS
    OSIUNITTEST_ASSERT_WARNING(test_status == 0, {}, "symphony", "testing MIPLIB");
#else
    if (test_status > 0)
      testingMessage( "Warning: some instances may not have returned a correct solution\n");
#endif
  }

  /*
    We're done. Report on the results.
  */
#ifdef COIN_HAS_OSITESTS
  std::cout.flush();
  outcomes.print();

  int nerrors;
  int nerrors_expected;
  outcomes.getCountBySeverity(TestOutcome::ERROR, nerrors, nerrors_expected);

  if (nerrors > nerrors_expected)
    std::cerr << "Tests completed with " << nerrors - nerrors_expected << " unexpected errors." << std::endl ;
  else
    std::cerr << "All tests completed successfully\n";

  return nerrors - nerrors_expected;
#else

  testingMessage( "All tests completed successfully\n" );

  return 0;
#endif
}
Example #10
0
int main(int argc, char **argv)
{

  OsiSymSolverInterface si;
  CoinWarmStart *ws;

  si.parseCommandLine(argc, argv);
  si.loadProblem();

  si.setSymParam(OsiSymKeepWarmStart, true);
  si.setSymParam(OsiSymNodeLimit, 100);

  si.initialSolve();
  ws = si.getWarmStart();
  si.setSymParam(OsiSymNodeLimit, 1000);

  si.resolve();

  si.setObjCoeff(0, 1);
  si.setObjCoeff(200, 150);
  si.setWarmStart(ws);

  si.resolve();

  return(0);

}