Example #1
0
  /** Ouptut a bonmin.opt file with options default values and short descritpions.*/
  void
  RegisteredOptions::writeBonminOpt(std::ostream &os, ExtraCategoriesInfo which){
      std::list< Ipopt::RegisteredOption * > options;
      chooseOptions(which, options);

      //Create journalist to write to os
      Ipopt::Journalist jnlst;
      Ipopt::SmartPtr<Ipopt::StreamJournal> J = new Ipopt::StreamJournal("options_journal", Ipopt::J_ALL);
      J->SetOutputStream(&os);
      J->SetPrintLevel(Ipopt::J_DOCUMENTATION, Ipopt::J_SUMMARY);
      jnlst.AddJournal(GetRawPtr(J));

      std::string registeringCategory = "";
      for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin();
           i != options.end() ; i++)
       {
          if((*i)->RegisteringCategory() != registeringCategory){
           registeringCategory = (*i)->RegisteringCategory();
             os<<std::endl<<"# registering category: "<<registeringCategory<<std::endl<<std::endl;
           }
           os<<"bonmin.";
           os.setf(std::ios::left);
           os.width(37);
           os<<(*i)->Name()<<" ";
           os.width(10);
           os<<makeNumber(defaultAsString(*i))<<"\t#";
           os<<(*i)->ShortDescription();
           os<<std::endl;            
       }
    }
Example #2
0
   /** Output Latex/Html options documentation.*/
   void 
   RegisteredOptions::writeLatexHtmlDoc(std::ostream &os, ExtraCategoriesInfo which){
      std::list< Ipopt::RegisteredOption * > options;
      chooseOptions(which, options);
      os<<"\\latexhtml{}{"<<std::endl;
      os<<"\\HCode{"<<std::endl;
      writeHtmlOptionsTable(os, options);
      os<<"}\n}"<<std::endl;

      //Create journalist to write to os
      Ipopt::Journalist jnlst;
      Ipopt::SmartPtr<Ipopt::StreamJournal> J = new Ipopt::StreamJournal("options_journal", Ipopt::J_ALL);
      J->SetOutputStream(&os);
      J->SetPrintLevel(Ipopt::J_DOCUMENTATION, Ipopt::J_SUMMARY);
      jnlst.AddJournal(GetRawPtr(J));

      std::string registeringCategory = "";
      for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin();
           i != options.end() ; i++)
       {
          if((*i)->RegisteringCategory() != registeringCategory){
           registeringCategory = (*i)->RegisteringCategory();
             os<<"\\subsection{"<<registeringCategory<<"}"<<std::endl;      
             os<<"\\label{sec:"<<makeSpaceLess(registeringCategory)<<"}"<<std::endl;
             os<<"\\htmlanchor{sec:"<<makeSpaceLess(registeringCategory)<<"}"<<std::endl;
           }
       
           (*i)->OutputLatexDescription(jnlst);
       }
    }
Example #3
0
  LpBranchingSolver::LpBranchingSolver(BabSetupBase * b) :
      StrongBranchingSolver(b->nonlinearSolver()),
      lin_(NULL),
      warm_(NULL),
      ecp_(NULL)
  {
    Ipopt::SmartPtr<TNLPSolver> tnlp_solver =
       static_cast<TNLPSolver *> (b->nonlinearSolver()->solver());
    Ipopt::SmartPtr<Ipopt::OptionsList> options = tnlp_solver->options();

	    options->GetIntegerValue("ecp_max_rounds_strong",
	                             maxCuttingPlaneIterations_,
                                     b->nonlinearSolver()->prefix());
	    options->GetNumericValue("ecp_abs_tol_strong",
                                     abs_ecp_tol_,
                                     b->nonlinearSolver()->prefix());
	    options->GetNumericValue("ecp_rel_tol_strong",
                                     rel_ecp_tol_,
                                     b->nonlinearSolver()->prefix());
	    int dummy;
	    options->GetEnumValue("lp_strong_warmstart_method", 
                                  dummy,
                                  b->nonlinearSolver()->prefix());
	    warm_start_mode_ = (WarmStartMethod) dummy;
	  }
void HeuristicInnerApproximation::registerOptions(Ipopt::SmartPtr<
    Bonmin::RegisteredOptions> roptions) {
  roptions->SetRegisteringCategory("Initial Approximations descriptions",
      RegisteredOptions::UndocumentedCategory);
  roptions->AddStringOption2("heuristic_inner_approximation",
      "if yes runs the InnerApproximation heuristic", "yes", "no",
      "don't run it", "yes", "runs the heuristic", "");

        roptions->setOptionExtraInfo("heuristic_inner_approximation", 63);
}
Example #5
0
 void
 LpBranchingSolver::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
 {
   roptions->SetRegisteringCategory("ECP based strong branching",RegisteredOptions::UndocumentedCategory);
   roptions->AddLowerBoundedIntegerOption
   ("ecp_max_rounds_strong",
    "Set the maximal number of rounds of ECP cuts in strong branching.",
    0,0,
    "");
   roptions->setOptionExtraInfo("ecp_max_rounds_strong",63);
   roptions->AddLowerBoundedNumberOption
   ("ecp_abs_tol_strong",
    "Set the absolute termination tolerance for ECP rounds in strong branching.",
    0,false,1e-6,
    "");
   roptions->setOptionExtraInfo("ecp_abs_tol_strong",63);
   roptions->AddLowerBoundedNumberOption
   ("ecp_rel_tol_strong",
    "Set the relative termination tolerance for ECP rounds in strong branching.",
    0,false,1e-1,
    "");
   roptions->setOptionExtraInfo("ecp_rel_tol_strong",63);
   roptions->AddStringOption2
   ("lp_strong_warmstart_method",
    "Choose method to use for warm starting lp in strong branching",
    "Basis",
    "Basis", "Use optimal basis of node",
    "Clone", "Clone optimal problem of node",
    "(Advanced stuff)");
   roptions->setOptionExtraInfo("lp_strong_warmstart_method",63);
 }
Example #6
0
 static std::string defaultAsString(Ipopt::SmartPtr< Ipopt::RegisteredOption > opt){
   Ipopt::RegisteredOptionType T = opt->Type();
   switch(T){
     case Ipopt::OT_Number: return makeString(opt->DefaultNumber());
     case Ipopt::OT_Integer: return makeString(opt->DefaultInteger());
     case Ipopt::OT_String: return (opt->DefaultString());
     case Ipopt::OT_Unknown: 
     default:
        return "Unknown type of option";
   }
 }
Example #7
0
 void
 MilpRounding::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
   roptions->SetRegisteringCategory("Primal Heuristics (undocumented)", RegisteredOptions::UndocumentedCategory);
  roptions->AddStringOption2(
    "MILP_rounding_heuristic",
    "if yes runs the heuristic",
    "no",
    "no", "don't run it",
    "yes", "runs the heuristic",
    "");
 }
 void
 HeuristicDiveVectorLength::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
   roptions->SetRegisteringCategory("Primal Heuristics", RegisteredOptions::BonminCategory);
  roptions->AddStringOption2(
    "heuristic_dive_vectorLength",
    "if yes runs the Dive VectorLength heuristic",
    "no",
    "no", "",
    "yes", "",
    "");
  roptions->setOptionExtraInfo("heuristic_dive_vectorLength", 63);
 }
 void
 FixAndSolveHeuristic::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
  roptions->SetRegisteringCategory("Test Heuristics", RegisteredOptions::UndocumentedCategory);
  roptions->AddStringOption2(
    "fix_and_solve_heuristic",
    "if yes runs a heuristic at root where fixes all variables integer in the continuous solution",
    "no",
    "no", "don't run it",
    "yes", "runs the heuristic",
    "");
  roptions->setOptionExtraInfo("fix_and_solve_heuristic", 63);
 }
Example #10
0
 BonNWayChoose::BonNWayChoose(BabSetupBase &b, const OsiSolverInterface* solver):
     OsiChooseVariable(solver),
     br_depth_(0),
     bounds_(),
     unit_changes_(),
     num_ps_costs_(),
     num_eval_(),
     geo_means_(0)
 {
   Ipopt::SmartPtr<Ipopt::OptionsList> options = b.options();
   options->GetNumericValue("time_limit", time_limit_, b.prefix());
   options->GetNumericValue("cutoff_multiplier", cutoff_multiplier_, b.prefix());
   options->GetNumericValue("pseudocost_trust_value", pseudocost_trust_value_, b.prefix());
   options->GetIntegerValue("strong_branch_depth", br_depth_, b.prefix());
   options->GetIntegerValue("nway_branch_log_level", log_, b.prefix());
   options->GetEnumValue("do_fixings", do_fixings_, b.prefix());
   options->GetEnumValue("use_geo_means", geo_means_, b.prefix());
   /** Set values of standard branching options.*/
   int numberObjects = solver_->numberObjects();
   std::cout<<"Number objects "<<numberObjects<<std::endl;
   start_time_ = CoinCpuTime();
   OsiObject ** object = solver->objects();
   for (int i=0;i<numberObjects;i++) {
      BonNWayObject * nway = dynamic_cast<BonNWayObject *>(object[i]);
     if(!nway) continue;
     start_nway_ = i;
     break;
   }
   numberObjects -= start_nway_;
 }
Example #11
0
  /** Register OA feasibility checker  options.*/
  void
  OaFeasibilityChecker::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
  {
    roptions->SetRegisteringCategory("Feasibility checker using OA cuts", RegisteredOptions::BonminCategory);
    roptions->AddStringOption2("feas_check_cut_types", "Choose the type of cuts generated when an integer feasible solution is found",
                               "outer-approx",
                               "outer-approx", "Generate a set of Outer Approximations cuts.",
                               "Benders", "Generate a single Benders cut.",
                               "If it seems too much memory is used should try Benders to use less");
    roptions->setOptionExtraInfo("feas_check_cut_types", 19);
    

    roptions->AddStringOption3("feas_check_discard_policy", "How cuts from feasibility checker are discarded",
                               "detect-cycles",
                               "detect-cycles", "Detect if a cycle occurs and only in this case force not to discard.",
                               "keep-all", "Force cuts from feasibility checker not to be discarded (memory hungry but sometimes better).",
                               "treated-as-normal", "Cuts from memory checker can be discarded as any other cuts (code may cycle then)",
                               "Normally to avoid cycle cuts from feasibility checker should not be discarded in the node where they are generated. "
                               "However Cbc sometimes does it if no care is taken which can lead to an infinite loop in Bonmin (usually on simple problems). "
                               "To avoid this one can instruct Cbc to never discard a cut but if we do that for all cuts it can lead to memory problems. "
                               "The default policy here is to detect cycles and only then impose to Cbc to keep the cut. "
                               "The two other alternative are to instruct Cbc to keep all cuts or to just ignore the problem and hope for the best");
    roptions->setOptionExtraInfo("feas_check_discard_policy", 19);

    roptions->AddLowerBoundedIntegerOption("generate_benders_after_so_many_oa", "Specify that after so many oa cuts have been generated Benders cuts should be generated instead.",
                                           0, 5000,
                                           "It seems that sometimes generating too many oa cuts slows down the optimization compared to Benders due to the size of the LP. "
                                           "With this option we specify that after so many OA cuts have been generated we should switch to Benders cuts.");
    roptions->setOptionExtraInfo("generate_benders_after_so_many_oa", 19);
  }
void setParameters(Ipopt::SmartPtr<Ipopt::OptionsList> options)
{
	const char *iptoptLinearSolver = getenv("IPOPT_LINEAR_SOLVER");
	if (!iptoptLinearSolver)
		iptoptLinearSolver = "ma57";
	options->SetStringValue("linear_solver", iptoptLinearSolver);
	if (!strcmp(iptoptLinearSolver, "ma27"))
	{
		/* This helps to improve performance from 0.6 to 0.5 sec */
		options->SetNumericValue("ma27_liw_init_factor", 100.);
		options->SetNumericValue("ma27_la_init_factor", 100.);
	}
	else if (!strcmp(iptoptLinearSolver, "ma57"))
	{
		/*
		 * Decreases performance from 0.04 to 0.13 sec:
		 * options->SetStringValue("ma57_automatic_scaling", "yes");
		 */

		/*
		 * Not evident, whether this helps to increase the performance,
		 * but it already helped to avoid memory reallocations.
		 */
		options->SetNumericValue("ma57_pre_alloc", 100.);
	}

	double ipoptTol = 0.;
	if (tryGetenvDouble("IPOPT_TOL", ipoptTol))
		options->SetNumericValue("tol", ipoptTol);

	double ipoptAcceptableTol = 0.;
	if (tryGetenvDouble("IPOPT_ACCEPTABLE_TOL", ipoptAcceptableTol))
		options->SetNumericValue("acceptable_tol", 1e-3);

	if (getenv("DERIVATIVE_TEST_FIRST"))
		options->SetStringValue("derivative_test", "first-order");
	else if (getenv("DERIVATIVE_TEST_SECOND"))
		options->SetStringValue("derivative_test", "second-order");
	else if (getenv("DERIVATIVE_TEST_ONLY_SECOND"))
		options->SetStringValue("derivative_test", "only-second-order");
	if (getenv("HESSIAN_APPROX"))
		options->SetStringValue("hessian_approximation",
				"limited-memory");

}
Example #13
0
  void RobotSetup::registerAllOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
  {
     BonminSetup::registerAllOptions(roptions);
     BonNWayChoose::registerOptions(roptions);


    roptions->AddLowerBoundedIntegerOption("branch_on_frac_only",
        "Starting at given depth branch on the subset of fractional variables (and set the last branch that one of them is 1)",
        0,INT_MAX,"");

    roptions->AddStringOption2("do_a_quick_one",
        "Do we try our luck?",
        "no",
        "no", "Don't (of course).",
        "yes", "Be crazy",
        "");

  }
Example #14
0
  void
  BonCbcFullNodeInfo::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
  {


    roptions->SetRegisteringCategory("Nonconvex problems", RegisteredOptions::BonminCategory);
    roptions->AddLowerBoundedIntegerOption("max_consecutive_infeasible",
        "Number of consecutive infeasible subproblems before aborting a"
        " branch.",
        0,0,
        "Will continue exploring a branch of the tree until \"max_consecutive_infeasible\""
        "consecutive problems are locally infeasible by the NLP sub-solver.");
    roptions->setOptionExtraInfo("max_consecutive_infeasible",8);

    roptions->SetRegisteringCategory("NLP solution robustness", RegisteredOptions::BonminCategory);
    roptions->AddLowerBoundedIntegerOption
    ("max_consecutive_failures",
     "(temporarily removed) Number $n$ of consecutive unsolved problems before aborting a branch of the tree.",
     0,10,
     "When $n > 0$, continue exploring a branch of the tree until $n$ "
     "consecutive problems in the branch are unsolved (we call unsolved a problem for which Ipopt can not "
     "guarantee optimality within the specified tolerances).");
    roptions->setOptionExtraInfo("max_consecutive_failures",8);

  }
Example #15
0
bool IASolverRelaxed::solve()
{
  
  // solve the nlp to get a non-integral solution, which we hope is close to a good integer solution    
  // adapted from HS071 ipopt example

  // p_norm set in constructor. 3 seems to work well, comes close to lex-max-min
  // smaller p has the effect of valuing the fidelity of shorter curves over longer curves more
  // larger p approaches min max
  IANlp *myianlp = new IANlp(iaData, iaSolution, silent);
  Ipopt::SmartPtr<TNLP> mynlp = myianlp; // Ipopt requires the use of smartptrs!
  
  Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
  app->Options()->SetNumericValue("tol", 1e-7); // 2 seems close enough, could do less, say .1
  app->Options()->SetStringValue("mu_strategy", "adaptive");
  // print level 0 to 12, most. Ipopt Default is 5
  int print_level = (silent) ? 0 : 1; // 1, 5
  // int print_level = 5;
  app->Options()->SetIntegerValue("print_level", print_level);  
  // uncomment next line to write the solution to an output file
  // app->Options()->SetStringValue("output_file", "IA.out");  
  // The following overwrites the default name (ipopt.opt) of the options file
  // app->Options()->SetStringValue("option_file_name", "IA.opt");
  
  // Intialize the IpoptApplication and process the options
  Ipopt::ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Ipopt::Solve_Succeeded) {
    if (!silent)
      printf("\n\n*** Error during ipopt initialization!\n");
    return (int) status;
  }
  
  // Ask Ipopt to solve the problem
  status = app->OptimizeTNLP(mynlp); // the inherited IANlp
  // todo: also check for a valid solution even if ! Solve_Succeeded, such as a sub-optimal time-out
  bool is_solved = (status == Ipopt::Solve_Succeeded);
  bool is_satisfied = is_solved && equal_constraints( false, debugging );
  // don't check even-ness, as those are like the integrality constraints and are not solved here
  
  if (!silent)
  {
    if (is_solved) {
      printf("\n\n*** The relaxed problem solved!");
      if (!is_satisfied)
        printf(" But equality-constraints were VIOLATED!");
      printf("\n");
    }
    else {
      printf("\n\n*** The relaxed problem FAILED!\n");
    }
  }
  return is_satisfied;
}  
void HeuristicInnerApproximation::registerOptions(Ipopt::SmartPtr<
    Bonmin::RegisteredOptions> roptions) {
  roptions->SetRegisteringCategory("Initial Approximations descriptions",
      Bonmin::RegisteredOptions::UndocumentedCategory);
  roptions->AddStringOption2("heuristic_inner_approximation",
      "if yes runs the InnerApproximation heuristic", "yes", "no",
      "don't run it", "yes", "runs the heuristic", "");

 roptions->setOptionExtraInfo("heuristic_inner_approximation", 63);

 roptions->AddLowerBoundedIntegerOption("number_inner_approximation_points",
       "Set the number of points to use for linear inner approximation of nonlinear functions in heuristic",
       1, 20);
 roptions->setOptionExtraInfo("number_inner_approximation_points", 63);

 roptions->AddLowerBoundedNumberOption("inner_time_limit",
       "Time limit for inner approximation",
       0, true, 10, "");
 roptions->setOptionExtraInfo("number_inner_approximation_points", 63);
}
IpoptSolution CppADSolver::solve(OptProblemData &data){
    size_t n = opt_prob->num_of_variables();
    size_t m = opt_prob->num_of_constraints();
    // create the Ipopt interface
    cppad_ipopt_solution solution;
    CppADOptProblemData cppad_data(data);
    Ipopt::SmartPtr<Ipopt::TNLP> cppad_nlp = new cppad_ipopt_nlp(
        n, m, cppad_data.x_i, cppad_data.x_l, cppad_data.x_u, cppad_data.g_l, cppad_data.g_u, &(*fg_info_ptr), &solution
        );

    // Create an instance of the IpoptApplication
    Ipopt::SmartPtr<Ipopt::IpoptApplication> app = new IpoptApplication();

    // turn off any printing
    app->Options()->SetIntegerValue("print_level", 4);
    app->Options()->SetStringValue("sb", "yes");

    // maximum number of iterations
    app->Options()->SetIntegerValue("max_iter", 5000);

    // approximate accuracy in first order necessary conditions;
    // see Mathematical Programming, Volume 106, Number 1, 
    // Pages 25-57, Equation (6)
    app->Options()->SetNumericValue("tol", 1e-9);

    // derivative testing
//    app->Options()->
//    SetStringValue("derivative_test", "second-order");
//    app->Options()-> SetNumericValue(
//            "point_perturbation_radius", 0.
//    );

    // Initialize the IpoptApplication and process the options
    Ipopt::ApplicationReturnStatus status = app->Initialize();
    assert(status == Ipopt::Solve_Succeeded);

    // Run the IpoptApplication
    status = app->OptimizeTNLP(cppad_nlp);
    return IpoptSolution(solution);
}
Example #18
0
  void
  BonNWayChoose::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
  {
    roptions->SetRegisteringCategory("NWay Strong branching setup", RegisteredOptions::BonminCategory);
    roptions->AddLowerBoundedIntegerOption("nway_branch_log_level",
                                           "Log level for the branching on nways",
                                           0,1,
                                           "");

    roptions->AddLowerBoundedIntegerOption("strong_branch_depth",
                                           "To which level do we perform strong-branching",
                                           0,0,
                                           "");

    roptions->AddLowerBoundedNumberOption("cutoff_multiplier",
                                           "multiplier applied to cutoff_ for computing pseudo-cost of infeasible sub-problems",
                                           1.,0,3.,
                                           "");

    roptions->AddLowerBoundedNumberOption("pseudocost_trust_value",
                                           "Trust pseudo cost of best nway object if it is above this value",
                                           0.,0,0,
                                           "");

    roptions->AddStringOption2("use_geo_means", "Use geometrical means to average pseudo-costs",
                               "yes", 
                               "no", "Use artihmetical means",
                               "yes", "Use geometrical means","");

    roptions->AddStringOption4("do_fixings",
        "Do we fix variables in strong branching?",
        "all",
        "none", "Don't do any.",
        "in-tree", "Fix only variables in the tree",
        "strong-branching", "Fix variable in strong branching only",
        "all", "Fix whenever possible",
        "");


  }
Example #19
0
  bool
  TNLPSolver::zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP>& tnlp, ReturnStatus &optimizationStatus)
  {

    int n,m,dum1, dum2;
    Ipopt::TNLP::IndexStyleEnum dum3;
    tnlp->get_nlp_info(n,m,dum1, dum2, dum3);
    double * x_l = new double[n];
    double * x_u = new double[n];
   
    double * g_l = (m>0) ? new double[m] : NULL;
    double * g_u = (m >0) ? new double[m] : NULL;
    
    tnlp->get_bounds_info(n, x_l, x_u, m, g_l , g_u);
    

    for(int i = 0 ; i < n ; i++) {
      if(x_u[i] - x_l[i] > 1e-5)
	{
	  delete [] x_l;
	  delete [] x_u;
          if(m > 0){
	    delete [] g_l;
	    delete [] g_u;
          }
	  return 0;
	}
    }

    //Problem has no variables just check if the unique solution given by the bounds is
    // feasible or not.
    double obj_value;

    tnlp->eval_f(n, x_l, true, obj_value);

    double * x_sol = new double[n];

      
    IpBlasDcopy(n, x_l, 1, x_sol, 1);

    delete [] x_l;
    delete [] x_u;

    double * g_sol = (m > 0) ? new double [m] : NULL;

    tnlp->eval_g(n, x_sol, true, m, g_sol);
    
    optimizationStatus = solvedOptimal;
    for(int i = 0 ; i < m ; i++) {
      if(g_sol[i] - g_l[i] <  - 1e-07 || g_sol[i] - g_u[i] > 1e-07) {
        optimizationStatus = provenInfeasible;
	
	delete [] g_l;
	delete [] g_u;
	double * lam = (m > 0) ? new double[m]: NULL;
	CoinFillN(lam,m,0.);
	double * z = new double[n];
	CoinFillN(z,n,0.);
	tnlp->finalize_solution(Ipopt::LOCAL_INFEASIBILITY,
			       n, x_sol, NULL, NULL, 
			       m, g_sol, NULL, obj_value, NULL, NULL);
	if (m > 0) delete [] lam;
	delete [] z;
	if (m > 0) delete [] g_sol;
	delete [] x_sol;

        return 1;
      }
    }
    if (m > 0) delete [] g_l;
    if (m > 0) delete [] g_u;

    double * lam = (m > 0) ? new double[m] : NULL;
    CoinFillN(lam,m,0.);
    double * z = new double[n];
    CoinFillN(z,n,0.);
    tnlp->finalize_solution(Ipopt::SUCCESS,
			   n, x_sol, z, z,
			   m, g_sol, lam, obj_value, NULL, NULL);
    if (m > 0) delete [] lam;
    delete [] z;
    if (m > 0) delete [] g_sol;
    delete [] x_sol;
    return 1;
  }
Example #20
0
void CouenneAmplInterface::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions) {
	roptions->AddStringOption1("nlfile", "name of an ampl .nl file to get the problem from", "", "*", "name of .nl file");
}
Example #21
0
void CouenneOSInterface::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions) {
	roptions->AddStringOption1("osilfile", "name of an osil file to read the problem instance from", "", "*", "name of osil file");
}
Example #22
0
bool multiple_solution(void)
{
	bool ok = true;
	// number of independent variables (domain dimension for f and g)
	size_t n = 2;
	// number of constraints (range dimension for g)
	size_t m = 2; 
	// initial value of the independent variables
	NumberVector x_i(n);
	NumberVector x_l(n);
	NumberVector x_u(n);

	size_t i = 0;
	for(i = 0; i < n; i++)
	{	x_i[i] = 0.;
		x_l[i] = -1.0;
		x_u[i] = +1.0;
	}

	// lower and upper limits for g
	NumberVector g_l(m);
	NumberVector g_u(m);
	g_l[0] = -1; g_u[0] = 0.;
	g_l[1] = 0.; g_u[1] = 1.;

	// object for evaluating function
	bool retape = false;
	FG_J_changes my_fg_info(retape);
	cppad_ipopt_fg_info *fg_info = &my_fg_info;

	cppad_ipopt_solution solution;
	Ipopt::SmartPtr<Ipopt::TNLP> cppad_nlp = new cppad_ipopt_nlp(
		n, m, x_i, x_l, x_u, g_l, g_u, fg_info, &solution
	);

	// Create an instance of the IpoptApplication
	using Ipopt::IpoptApplication;
	Ipopt::SmartPtr<IpoptApplication> app = new IpoptApplication();

	// turn off any printing
	app->Options()->SetIntegerValue("print_level", 0);
	app->Options()->SetStringValue("sb", "yes");

	// approximate accuracy in first order necessary conditions;
	// see Mathematical Programming, Volume 106, Number 1,
	// Pages 25-57, Equation (6)
	app->Options()->SetNumericValue("tol", 1e-9);
	app->Options()-> SetStringValue("derivative_test", "second-order");

	// Initialize the IpoptApplication and process the options
	Ipopt::ApplicationReturnStatus status = app->Initialize();
	ok    &= status == Ipopt::Solve_Succeeded;

	// Run the IpoptApplication
	status = app->OptimizeTNLP(cppad_nlp);
	ok    &= status == Ipopt::Solve_Succeeded;

	/*
	 Check solution status
	 */
	ok &= solution.status == cppad_ipopt_solution::success;
	ok &= CppAD::NearEqual(solution.x[1], 0., 1e-6, 1e-6);

	return ok;
}
Example #23
0
bool IASolverInt::solve_wave_workhorse(IAIntWaveNlp *mynlp)
{
  if (debugging)
  {
    printf("IASolverInt::solve_wave() - ");        
    printf("Attempting to enforce an integer and even solution to the relaxed NLP by adding constraints that repeat wave-like at each integer lattice point.\n");
  }
  
  // solver setup  
  Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
/* try leaving defaults
  // convergence parameters
  // see $IPOPTDIR/Ipopt/src/Interfaces/IpIpoptApplication.cpp
  // our real criteria are: all integer, constraints satisfied. How to test the "all_integer" part?
  app->Options()->SetNumericValue("tol", 1e-6); //"converged" if NLP error<this, default is 1e-7. Obj are scaled to be >1, so e-2 is plenty // was 1e-2
  app->Options()->SetNumericValue("max_cpu_time", sqrt( iaData->num_variables() ) ); // max time allowed in seconds
  app->Options()->SetIntegerValue("max_iter", 3 * (10 + iaData->num_variables() ) ); // max number of iterations
  // app->Options()->SetNumericValue("primal_inf_tol", 1e-2 ); 
  app->Options()->SetNumericValue("dual_inf_tol", 1e-2 ); // how close to infeasibility? // was 1e-2
  app->Options()->SetNumericValue("constr_viol_tol", 1e-2 ); // by how much can constraints be violated?
  app->Options()->SetNumericValue("compl_inf_tol", 1e-6 ); // max norm of complementary condition // was 1e-2
  
  // second criteria convergence parameters: quit if within this tol for many iterations
  // was  app->Options()->SetIntegerValue("acceptable_iter", 4 + sqrt( iaData->num_variables() ) ); //as "tol"
  app->Options()->SetNumericValue("acceptable_tol", 1e-6 ); //as "tol" was 1e-1
  
  app->Options()->SetStringValue("mu_strategy", "adaptive");
  // print level 0 to 12, Ipopt default is 5
  const int print_level = (silent) ? 0 : 1;  // simple info is 1, debug at other values
  app->Options()->SetIntegerValue("print_level", print_level);  
  // uncomment next line to write the solution to an output file
  // app->Options()->SetStringValue("output_file", "IA.out");  
  // The following overwrites the default name (ipopt.opt) of the options file
  // app->Options()->SetStringValue("option_file_name", "IA.opt");
  
  */
  
  // Intialize the IpoptApplication and process the options
  Ipopt::ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Ipopt::Solve_Succeeded) {
    if (!silent)
      printf("\n\n*** Error during initialization!\n");
    return (int) status;
  }
  
  bool try_again = true;
  int iter = 0;
  
  // print();
  bool solution_ok = false;
  
  do {
    if (debugging)
    {
      print();
      printf("%d IntWave iteration\n", iter );
      // build the hessian, evaluate it and f at the current solution?
    }
      
    // Ask Ipopt to solve the problem
    status = app->OptimizeTNLP(mynlp); // the inherited IANlp
    
    // see /CoinIpopt/build/include/coin/IpReturnCodes_inc.h
    /*
    Solve_Succeeded=0,
    Solved_To_Acceptable_Level=1,
    Infeasible_Problem_Detected=2,
    Search_Direction_Becomes_Too_Small=3,
    Diverging_Iterates=4,
    User_Requested_Stop=5,
    Feasible_Point_Found=6,
    
    Maximum_Iterations_Exceeded=-1,
    Restoration_Failed=-2,
    Error_In_Step_Computation=-3,
    Maximum_CpuTime_Exceeded=-4,
    Not_Enough_Degrees_Of_Freedom=-10,
    Invalid_Problem_Definition=-11,
    Invalid_Option=-12,
    Invalid_Number_Detected=-13,
    
    Unrecoverable_Exception=-100,
    NonIpopt_Exception_Thrown=-101,
    Insufficient_Memory=-102,
    Internal_Error=-199
     */

    bool solved_full = false;
    bool solved_partial = false;
    bool solver_failed = false;
    bool bad_problem = false;

    switch (status) {
      case Ipopt::Solve_Succeeded:
      case Ipopt::Solved_To_Acceptable_Level:
      case Ipopt::Feasible_Point_Found:
        solved_full = true;
        break;
      case Ipopt::Maximum_Iterations_Exceeded:
      case Ipopt::User_Requested_Stop:
      case Ipopt::Maximum_CpuTime_Exceeded:
        solved_partial = true;
        break;
      case Ipopt::Infeasible_Problem_Detected:
      case Ipopt::Not_Enough_Degrees_Of_Freedom:
      case Ipopt::Invalid_Problem_Definition:
      case Ipopt::Invalid_Option:
      case Ipopt::Invalid_Number_Detected:
        bad_problem = true;
        break;
      case Ipopt::Search_Direction_Becomes_Too_Small:
      case Ipopt::Restoration_Failed:
      case Ipopt::Diverging_Iterates:
      case Ipopt::Error_In_Step_Computation:
      case Ipopt::Unrecoverable_Exception:
      case Ipopt::NonIpopt_Exception_Thrown:
      case Ipopt::Insufficient_Memory:
      case Ipopt::Internal_Error:        
        solver_failed = true;
        break;
        
      default:
        break;
    }
  
    if (!silent)
    {
      if (solved_full) {
        printf("\n\n*** IntWave solved!\n");
      }
      else {
        printf("\n\n*** IntWave FAILED!\n");
      }
    }
    
    if (debugging)
    {
      printf("\nChecking solution.\n");
      bool integer_sat = solution_is_integer(true);
      bool even_sat = even_constraints( false, true);
      bool equal_sat = equal_constraints( false, true );
      printf("IntWave solution summary, %s, equal-constraints %s, even-constraints %s.\n", 
             integer_sat ? "integer" : "NON-INTEGER",
             equal_sat ? "satisfied" : "VIOLATED", 
             even_sat ? "satisfied" : "VIOLATED" );
      if (!integer_sat)
        printf("investigate integer neighborhood\n");
      if (!even_sat)
        printf("investigate even neighborhood\n");
      if (!equal_sat)
        printf("investigate equal neighborhood\n");
    }
    
    
    IASolution nlp_solution;
    nlp_solution.x_solution = ia_solution()->x_solution; // vector copy
    IASolverToolInt sti( ia_data(), &nlp_solution );
    sti.round_solution();
    if (debugging)
      printf("Checking rounded solution, ignoring even constraints.\n");
    if (sti.equal_constraints(false, debugging))
    {
      // also even constraints
      if (debugging)
        printf("Rounding worked.\n");
      
      // rounding was a valid integer solution
      ia_solution()->x_solution.swap( nlp_solution.x_solution );
      // ia_solution()->obj_value is no longer accurate, as it was for the non-rounded solution
      return true;
    }
    
    // todo: detect and act
    // may have converged to a locally optimal, but non-feasible solution
    // if so, try a new starting point
    
    // check solution feasibility, even when not debugging
    
    if ( solved_full || solved_partial )
    {
      bool integer_sat = solution_is_integer(false);
      bool even_sat = even_constraints( false, false);
      bool equal_sat = equal_constraints( false, false );
      if ( integer_sat && even_sat && equal_sat )
        return true;
    }

    // find out which vars were not integer, 
    // try moving to a farther starting point resolving
    
 
    try_again = false; 
  } while (try_again);
  
  
  // now 
  // As the SmartPtrs go out of scope, the reference count
  // will be decremented and the objects will automatically
  // be deleted.  
  return solution_ok;
  
}
Example #24
0
void solve(
	const std::string&                   options   ,
	const Dvector&                       xi        ,
	const Dvector&                       xl        ,
	const Dvector&                       xu        ,
	const Dvector&                       gl        ,
	const Dvector&                       gu        ,
	FG_eval&                             fg_eval   ,
	ipopt::solve_result<Dvector>&        solution  )
{	bool ok = true;

	typedef typename FG_eval::ADvector ADvector;

	CPPAD_ASSERT_KNOWN(
		xi.size() == xl.size() && xi.size() == xu.size() ,
		"ipopt::solve: size of xi, xl, and xu are not all equal."
	);
	CPPAD_ASSERT_KNOWN(
		gl.size() == gu.size() ,
		"ipopt::solve: size of gl and gu are not equal."
	);
	size_t nx = xi.size();
	size_t ng = gl.size();

	// Create an IpoptApplication
	using Ipopt::IpoptApplication;
	Ipopt::SmartPtr<IpoptApplication> app = new IpoptApplication();

	// process the options argument
	size_t begin_1, end_1, begin_2, end_2, begin_3, end_3;
	begin_1     = 0;
	bool retape          = false;
	bool sparse_forward  = false;
	bool sparse_reverse  = false;
	while( begin_1 < options.size() )
	{	// split this line into tokens
		while( options[begin_1] == ' ')
			begin_1++;
		end_1   = options.find_first_of(" \n", begin_1);
		begin_2 = end_1;
		while( options[begin_2] == ' ')
			begin_2++;
		end_2   = options.find_first_of(" \n", begin_2);
		begin_3 = end_2;
		while( options[begin_3] == ' ')
			begin_3++;
		end_3   = options.find_first_of(" \n", begin_3);

		// check for errors
		CPPAD_ASSERT_KNOWN(
			(end_1 != std::string::npos)  &
			(end_2 != std::string::npos)  &
			(end_3 != std::string::npos)  ,
			"ipopt::solve: missing '\\n' at end of an option line"
		);
		CPPAD_ASSERT_KNOWN(
			(end_1 > begin_1) & (end_2 > begin_2) ,
			"ipopt::solve: an option line does not have two tokens"
		);

		// get first two tokens
		std::string tok_1 = options.substr(begin_1, end_1 - begin_1);
		std::string tok_2 = options.substr(begin_2, end_2 - begin_2);

		// get third token
		std::string tok_3;
		bool three_tok = false;
		three_tok |= tok_1 == "Sparse";
		three_tok |= tok_1 == "String";
		three_tok |= tok_1 == "Numeric";
		three_tok |= tok_1 == "Integer";
		if( three_tok )
		{	CPPAD_ASSERT_KNOWN(
				(end_3 > begin_3) ,
				"ipopt::solve: a Sparse, String, Numeric, or Integer\n"
				"option line does not have three tokens."
			);
			tok_3 = options.substr(begin_3, end_3 - begin_3);
		}

		// switch on option type
		if( tok_1 == "Retape" )
		{	CPPAD_ASSERT_KNOWN(
				(tok_2 == "true") | (tok_2 == "false") ,
				"ipopt::solve: Retape value is not true or false"
			);
			retape = (tok_2 == "true");
		}
		else if( tok_1 == "Sparse" )
		{	CPPAD_ASSERT_KNOWN(
				(tok_2 == "true") | (tok_2 == "false") ,
				"ipopt::solve: Sparse value is not true or false"
			);
			CPPAD_ASSERT_KNOWN(
				(tok_3 == "forward") | (tok_3 == "reverse") ,
				"ipopt::solve: Sparse direction is not forward or reverse"
			);
			if( tok_2 == "false" )
			{	sparse_forward = false;
				sparse_reverse = false;
			}
			else
			{	sparse_forward = tok_3 == "forward";
				sparse_reverse = tok_3 == "reverse";
			}
		}
		else if ( tok_1 == "String" )
			app->Options()->SetStringValue(tok_2.c_str(), tok_3.c_str());
		else if ( tok_1 == "Numeric" )
		{	Ipopt::Number value = std::atof( tok_3.c_str() );
			app->Options()->SetNumericValue(tok_2.c_str(), value);
		}
		else if ( tok_1 == "Integer" )
		{	Ipopt::Index value = std::atoi( tok_3.c_str() );
			app->Options()->SetIntegerValue(tok_2.c_str(), value);
		}
		else	CPPAD_ASSERT_KNOWN(
			false,
			"ipopt::solve: First token is not one of\n"
			"Retape, Sparse, String, Numeric, Integer"
		);

		begin_1 = end_3;
		while( options[begin_1] == ' ')
			begin_1++;
		if( options[begin_1] != '\n' ) CPPAD_ASSERT_KNOWN(
			false,
			"ipopt::solve: either more than three tokens "
			"or no '\\n' at end of a line"
		);
		begin_1++;
	}
	CPPAD_ASSERT_KNOWN(
		! ( retape & (sparse_forward | sparse_reverse) ) ,
		"ipopt::solve: retape and sparse both true is not supported."
	);

	// Initialize the IpoptApplication and process the options
	Ipopt::ApplicationReturnStatus status = app->Initialize();
	ok    &= status == Ipopt::Solve_Succeeded;
	if( ! ok )
	{	solution.status = solve_result<Dvector>::unknown;
		return;
	}

	// Create an interface from Ipopt to this specific problem.
	// Note the assumption here that ADvector is same as cppd_ipopt::ADvector
	size_t nf = 1;
	Ipopt::SmartPtr<Ipopt::TNLP> cppad_nlp =
	new CppAD::ipopt::solve_callback<Dvector, ADvector, FG_eval>(
		nf,
		nx,
		ng,
		xi,
		xl,
		xu,
		gl,
		gu,
		fg_eval,
		retape,
		sparse_forward,
		sparse_reverse,
		solution
	);

	// Run the IpoptApplication
	app->OptimizeTNLP(cppad_nlp);

	return;
}
Example #25
0
bool k_gt_one(void)
{	bool ok = true;
	size_t j;


	// number of independent variables (domain dimension for f and g)
	size_t n = 4;  
	// number of constraints (range dimension for g)
	size_t m = 2;
	// initial value of the independent variables
	NumberVector x_i(n);
	x_i[0] = 1.0;
	x_i[1] = 5.0;
	x_i[2] = 5.0;
	x_i[3] = 1.0;
	// lower and upper limits for x
	NumberVector x_l(n);
	NumberVector x_u(n);
	for(j = 0; j < n; j++)
	{	x_l[j] = 1.0;
		x_u[j] = 5.0;
	}
	// lower and upper limits for g
	NumberVector g_l(m);
	NumberVector g_u(m);
	g_l[0] = 25.0;     g_u[0] = 1.0e19;
  	g_l[1] = 40.0;     g_u[1] = 40.0;

	// known solution to check against
	double check_x[]   = { 1.000000, 4.743000, 3.82115, 1.379408 };

	size_t icase;
	for(icase = 0; icase <= 1; icase++)
	{	// Should cppad_ipopt_nlp retape the operation sequence for
		// every new x. Can test both true and false cases because 
		// the operation sequence does not depend on x (for this case).
		bool retape = bool(icase);

		// check case where upper and lower limits are equal
		if( icase == 1 )
		{	x_l[2] = check_x[2];
			x_u[2] = check_x[2];
		}

		// object in derived class
		FG_K_gt_one my_fg_info(retape);
		cppad_ipopt_fg_info *fg_info = &my_fg_info;  

		// create the Ipopt interface
		cppad_ipopt_solution solution;
		Ipopt::SmartPtr<Ipopt::TNLP> cppad_nlp = new cppad_ipopt_nlp(
		n, m, x_i, x_l, x_u, g_l, g_u, fg_info, &solution
		);

		// Create an instance of the IpoptApplication
		using Ipopt::IpoptApplication;
		Ipopt::SmartPtr<IpoptApplication> app = new IpoptApplication();

		// turn off any printing
		app->Options()->SetIntegerValue("print_level", 0);

		// maximum number of iterations
		app->Options()->SetIntegerValue("max_iter", 10);

		// approximate accuracy in first order necessary conditions;
		// see Mathematical Programming, Volume 106, Number 1, 
		// Pages 25-57, Equation (6)
		app->Options()->SetNumericValue("tol", 1e-9);

		// derivative testing
		app->Options()->
		SetStringValue("derivative_test", "second-order");

		// Initialize the IpoptApplication and process the options
		Ipopt::ApplicationReturnStatus status = app->Initialize();
		ok    &= status == Ipopt::Solve_Succeeded;

		// Run the IpoptApplication
		status = app->OptimizeTNLP(cppad_nlp);
		ok    &= status == Ipopt::Solve_Succeeded;

		/*
 		Check some of the solution values
 		*/
		ok &= solution.status == cppad_ipopt_solution::success;
		//
		double check_z_l[] = { 1.087871, 0.,       0.,      0.       };
		double check_z_u[] = { 0.,       0.,       0.,      0.       };
		double rel_tol     = 1e-6;  // relative tolerance
		double abs_tol     = 1e-6;  // absolute tolerance
		for(j = 0; j < n; j++)
		{	ok &= CppAD::NearEqual(
			check_x[j],   solution.x[j],   rel_tol, abs_tol
			);
			ok &= CppAD::NearEqual(
			check_z_l[j], solution.z_l[j], rel_tol, abs_tol
			);
			ok &= CppAD::NearEqual(
			check_z_u[j], solution.z_u[j], rel_tol, abs_tol
			);
		}
	}

	return ok;
}
Example #26
0
bool IASolverInt::solve_round()
{
  // set up and call the separate IARoundingNlp, which has a linear objective to get a natural integer solution 
  // the intuition is this will solve integrality for  most variables all at once

  if (debugging)
  {
    printf("IASolverInt::solve_bend_workhorse() - ");        
  }

  
  // solver setup  
  Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
  
  // convergence parameters
  // see $IPOPTDIR/Ipopt/src/Interfaces/IpIpoptApplication.cpp
  // our real criteria are: all integer, constraints satisfied. How to test the "all_integer" part?
  app->Options()->SetNumericValue("tol", 1e-6); //"converged" if NLP error<this, default is 1e-7. Obj are scaled to be >1, so e-2 is plenty // was 1e-2
  app->Options()->SetNumericValue("max_cpu_time", sqrt( iaData->num_variables() ) ); // max time allowed in seconds
  app->Options()->SetIntegerValue("max_iter", 3 * iaData->num_variables() ); // max number of iterations
  // app->Options()->SetNumericValue("primal_inf_tol", 1e-2 ); 
  app->Options()->SetNumericValue("dual_inf_tol", 1e-6 ); // how close to infeasibility? // was 1e-2
  app->Options()->SetNumericValue("constr_viol_tol", 1e-6 ); // by how much can constraints be violated?
  app->Options()->SetNumericValue("compl_inf_tol", 1e-6 ); // max norm of complementary condition // was 1e-2

  // second criteria convergence parameters: quit if within this tol for many iterations
// was  app->Options()->SetIntegerValue("acceptable_iter", 4 + sqrt( iaData->num_variables() ) ); //as "tol"
  app->Options()->SetNumericValue("acceptable_tol", 1e-6 ); //as "tol" was 1e-1

  app->Options()->SetStringValue("mu_strategy", "adaptive");
  // print level 0 to 12, Ipopt default is 5
  const int print_level = (silent) ? 0 : 1; 
  app->Options()->SetIntegerValue("print_level", print_level);  
  // uncomment next line to write the solution to an output file
  // app->Options()->SetStringValue("output_file", "IA.out");  
  // The following overwrites the default name (ipopt.opt) of the options file
  // app->Options()->SetStringValue("option_file_name", "IA.opt");
  
  // Intialize the IpoptApplication and process the options
  Ipopt::ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Ipopt::Solve_Succeeded) {
    if (!silent)
      printf("\n\n*** Error during initialization!\n");
    return (int) status;
  }
  
  
  Ipopt::TNLP *tnlp = NULL;

  IARoundingNlp *myianlp = new IARoundingNlp(iaData, ipData, iaSolution, silent);
  if (debugging) 
  {          
    printf("ROUNDING problem formulation\n");
    printf("Attempting to find a naturally-integer solution by linearizing the objective function.\n");
    printf("Variables are constrained within [floor,ceil] of relaxed solution.\n");
  }
  
  // problem setup
  // a couple of different models, simplest to more complex
  // IARoundingFarNlp *myianlp = new IARoundingFarNlp(iaData, ipData, this);
  // IARoundingFar3StepNlp *myianlp = new IARoundingFar3StepNlp(iaData, ipData, this); // haven't tested this. It compiles and runs but perhaps isn't correct
  // IAIntWaveNlp *myianlp = new IAIntWaveNlp(iaData, ipData, this); // haven't tested this. It compiles and runs but perhaps isn't correct

  tnlp = myianlp;
  Ipopt::SmartPtr<Ipopt::TNLP> mynlp = tnlp; // Ipopt requires the use of smartptrs!

  bool try_again = true;
  int iter = 0;
  do {
    printf("%d rounding iteration\n", iter );
    
    // Ask Ipopt to solve the problem
    status = app->OptimizeTNLP(mynlp); // the inherited IANlp
    
    if (!silent)
    {
      if (status == Ipopt::Solve_Succeeded) {
        printf("\n\n*** The problem solved!\n");
      }
      else {
        printf("\n\n*** The problem FAILED!\n");
      }
    }
    
    // The problem should have been feasible, but it is possible that it had no integer solution.
    // figure out which variables are still integer
    
    // check solution for integrality and constraint satified    
    if (debugging)
    {
      printf("\nChecking Natural (non-rounded) solution.\n");
      bool integer_sat = solution_is_integer(true);
      bool even_sat = even_constraints( false, true);
            bool equal_sat = equal_constraints( false, true );
      printf("Natural solution summary, %s, equal-constraints %s, even-constraints %s.\n", 
             integer_sat ? "integer" : "NON-INTEGER",
             equal_sat ? "satisfied" : "VIOLATED", 
             even_sat ? "satisfied" : "VIOLATED" );
      if (!integer_sat)
        printf("investigate this\n");
    }
    
    IASolution nlp_solution;
    nlp_solution.x_solution = ia_solution()->x_solution; // vector copy
    IASolverToolInt sti( ia_data(), &nlp_solution );
    sti.round_solution();
    if (debugging)
      printf("Checking rounded solution, ignoring even constraints.\n");
    if (sti.equal_constraints(false, debugging))
    {
      // also even constraints
      if (debugging)
        printf("Rounding worked.\n");

      // rounding was a valid integer solution
      ia_solution()->x_solution.swap( nlp_solution.x_solution );
      // ia_solution()->obj_value is no longer accurate, as it was for the non-rounded solution
      return true;
    }

    // find out which vars were not integer, 
    // try rounding their weights and resolving
    // bool int_sat = solution_is_integer();
    ++iter;
    try_again = iter < 4 + sqrt(iaData->num_variables());
    if (try_again)
    {
      if (debugging)
        printf("rounding failed, randomizing weights\n");
    
      myianlp->randomize_weights_of_non_int(); // try again? debug
    }
    else if (debugging)
      printf("giving up on rounding to non-integer solution\n");

    // try_again = false; // debug
  } while (try_again);

  
  // todo: update partially-integer solution, perhaps using ipData - figure out how we're going to use it, first, for what structure makes sense.
  
  // As the SmartPtrs go out of scope, the reference count
  // will be decremented and the objects will automatically
  // be deleted.  
  return status == Ipopt::Solve_Succeeded;
  
}
Example #27
0
EngineStatus IpoptEngine::solve()
{
  Ipopt::ApplicationReturnStatus status = Ipopt::Internal_Error; 
  bool should_stop;

  stats_->calls += 1;
  if (!(bndChanged_ || consChanged_)) {
    return status_;
  }
  // Check if warm start is enabled. If so, load the information and
  // resolve. Otherwise solve from scratch.
  if (useWs_ && ws_ && ws_->hasInfo()) {
    myapp_->Options()->SetStringValue("warm_start_init_point", "yes");
    if (true == strBr_) {
      mynlp_->copySolution(ws_->getPoint());
    } else {
      mynlp_->setSolution(ws_->getPoint());
    }
  } else {
    myapp_->Options()->SetStringValue("warm_start_init_point", "no");
  }

  if (consChanged_) {
    problem_->prepareForSolve(); // reset hessian and jacobian structures.
    setOptionsForProb_();
  }
  // Ask Ipopt to solve the problem. In order to do that, one should convert
  // mynlp_ from the derived class IpoptFunInterface (that we define) to
  // Ipopt::TNLP
  status_ = EngineUnknownStatus;
  //Ipopt::SmartPtr<Ipopt::TNLP> base = Ipopt::SmartPtr<Ipopt::TNLP>
  //(&(*mynlp_));
  timer_->start();
  should_stop = presolve_();
  stats_->ptime += timer_->query();
  if (should_stop) {
    if (status_== ProvenLocalOptimal) {
      status = Ipopt::Solve_Succeeded;
    } else if (status_ == ProvenLocalInfeasible) {
      status = Ipopt::Infeasible_Problem_Detected;
    }
  } else if (ws_ && ws_->hasInfo() && stats_->calls > 1) {
    status = myapp_->ReOptimizeTNLP(mynlp_);
  } else {
    status = myapp_->OptimizeTNLP(mynlp_);
  }

#if SPEW
  logger_->msgStream(LogDebug) << me_ << "time taken = " << timer_->query() 
    << std::endl;
  logger_->msgStream(LogDebug) << me_ << "Ipopt's status = " << status 
    << std::endl;
#endif
  //exit(0);

  // See IpReturnCodes_inc.h for the list
  switch (status) {
   case Ipopt::Solve_Succeeded : 
     status_ = ProvenLocalOptimal;
     sol_ = mynlp_->getSolution();
     break;
   case Ipopt::Solved_To_Acceptable_Level :
     status_ = ProvenLocalOptimal;
     sol_ = mynlp_->getSolution();
     break;
   case Ipopt::Infeasible_Problem_Detected :
     status_ = ProvenLocalInfeasible;
     break;
   case Ipopt::Maximum_Iterations_Exceeded :
     status_ = EngineIterationLimit;
     break;
   case Ipopt::Maximum_CpuTime_Exceeded :
     status_ = EngineIterationLimit;
     break;
   case Ipopt::Restoration_Failed :  // don't know what else to do.
     logger_->msgStream(LogInfo) << me_ << "restoration failed, "
       << "assuming local infeasible." << std::endl;
     status_ = ProvenLocalInfeasible;
     sol_ = mynlp_->getSolution();
     break;
   case Ipopt::Diverging_Iterates :
     status_ = ProvenUnbounded;
     break;
   case Ipopt::Search_Direction_Becomes_Too_Small :
     assert(!"Ipopt: search direction becomes too small.");
     break;
   case Ipopt::User_Requested_Stop:
     assert(!"Ipopt: user requested stop.");
     break;
   case Ipopt::Feasible_Point_Found:
     assert(!"Ipopt: feasible point found.");
     break;
   case Ipopt::Error_In_Step_Computation:
   case Ipopt::Not_Enough_Degrees_Of_Freedom:
   case Ipopt::Invalid_Problem_Definition:
   case Ipopt::Invalid_Option:
   case Ipopt::Invalid_Number_Detected:
   case Ipopt::Unrecoverable_Exception:
   case Ipopt::NonIpopt_Exception_Thrown:
   case Ipopt::Insufficient_Memory:
   case Ipopt::Internal_Error:
   default:
     logger_->msgStream(LogNone) << me_ << "error reported." << std::endl;
     status_ = EngineError;
  }
  if (prepareWs_) {
    // save warm start information
    ws_->setPoint(sol_);
  }

  Ipopt::SmartPtr<Ipopt::SolveStatistics> stats = myapp_->Statistics();
  // sometimes, (e.g. when all variables are fixed) ipopt does not solve
  // anything returns an empty Statistics object.
  UInt iters = (Ipopt::IsValid(stats)) ? stats->IterationCount() : 0;
#if SPEW
  logger_->msgStream(LogDebug) << me_ << "solve number = " << stats_->calls
    << std::endl;
  logger_->msgStream(LogDebug) << me_ << "number of iterations = " << iters 
    << std::endl;
  logger_->msgStream(LogDebug) << me_ << "status = " << getStatusString() 
    << std::endl;
  logger_->msgStream(LogDebug) << me_ << "obj = ";
  if (sol_) {
    logger_->msgStream(LogDebug) << mynlp_->getSolutionValue() << std::endl;
  } else {
    logger_->msgStream(LogDebug) << 1e40 << std::endl;
  }
#endif 
  if (true == strBr_) {
    stats_->strCalls += 1;
    stats_->strTime  += timer_->query();
    stats_->strIters += iters;
  } 
  stats_->time  += timer_->query();
  stats_->iters += iters;
  timer_->stop();

  bndChanged_ = false;
  consChanged_ = false;
  return status_;
}
Example #28
0
bool retape_k1_l1(void)
{   bool ok = true;
    size_t j;


    // number of independent variables (domain dimension for f and g)
    size_t n = 2;
    // number of constraints (range dimension for g)
    size_t m = 1;
    // initial value of the independent variables
    NumberVector x_i(n);
    x_i[0] = 2.0;
    x_i[1] = 2.0;
    // lower and upper limits for x
    NumberVector x_l(n);
    NumberVector x_u(n);
    for(j = 0; j < n; j++)
    {   x_l[j] = -10.;
        x_u[j] = +10.;
    }
    // lower and upper limits for g
    NumberVector g_l(m);
    NumberVector g_u(m);
    g_l[0] = -1.;
    g_u[0] = 1.0e19;

    // object in derived class
    FG_retape fg_retape;
    cppad_ipopt_fg_info *fg_info = &fg_retape;

    // create the Ipopt interface
    cppad_ipopt_solution solution;
    Ipopt::SmartPtr<Ipopt::TNLP> cppad_nlp = new cppad_ipopt_nlp(
        n, m, x_i, x_l, x_u, g_l, g_u, fg_info, &solution
    );

    // Create an instance of the IpoptApplication
    using Ipopt::IpoptApplication;
    Ipopt::SmartPtr<IpoptApplication> app = new IpoptApplication();

    // turn off any printing
    app->Options()->SetIntegerValue("print_level", 0);
    app->Options()->SetStringValue("sb", "yes");

    // maximum number of iterations
    app->Options()->SetIntegerValue("max_iter", 10);

    // approximate accuracy in first order necessary conditions;
    // see Mathematical Programming, Volume 106, Number 1,
    // Pages 25-57, Equation (6)
    app->Options()->SetNumericValue("tol", 1e-9);

    // derivative testing
    app->Options()->
    SetStringValue("derivative_test", "second-order");

    // Initialize the IpoptApplication and process the options
    Ipopt::ApplicationReturnStatus status = app->Initialize();
    ok    &= status == Ipopt::Solve_Succeeded;

    // Run the IpoptApplication
    status = app->OptimizeTNLP(cppad_nlp);
    ok    &= status == Ipopt::Solve_Succeeded;

    /*
    Check some of the solution values
    */
    ok &= solution.status == cppad_ipopt_solution::success;
    //
    double check_x[]   = { -1., 0. };
    double rel_tol     = 1e-6;  // relative tolerance
    double abs_tol     = 1e-6;  // absolute tolerance
    for(j = 0; j < n; j++)
    {   ok &= CppAD::NearEqual(
                  check_x[j],   solution.x[j],   rel_tol, abs_tol
              );
    }

    return ok;
}
Example #29
0
void CouenneSetup::registerAllOptions (Ipopt::SmartPtr <Bonmin::RegisteredOptions> roptions) {

  roptions -> SetRegisteringCategory ("Couenne options", Bonmin::RegisteredOptions::CouenneCategory);

  BabSetupBase        ::registerAllOptions (roptions);
  Bonmin::BonCbcFullNodeInfo  ::registerOptions (roptions);

  /// Heuristics
  Bonmin::LocalSolverBasedHeuristic    ::registerOptions (roptions);
  Bonmin::FixAndSolveHeuristic         ::registerOptions (roptions);
  Bonmin::DummyPump                    ::registerOptions (roptions);
  Bonmin::MilpRounding                 ::registerOptions (roptions);
  Bonmin::PumpForMinlp                 ::registerOptions (roptions);
  Bonmin::HeuristicRINS                ::registerOptions (roptions);
  Bonmin::HeuristicLocalBranching      ::registerOptions (roptions);
  Bonmin::HeuristicFPump               ::registerOptions (roptions);
  Bonmin::HeuristicDiveFractional      ::registerOptions (roptions);
  Bonmin::HeuristicDiveVectorLength    ::registerOptions (roptions);
  Bonmin::HeuristicDiveMIPFractional   ::registerOptions (roptions);
  Bonmin::HeuristicDiveMIPVectorLength ::registerOptions (roptions);  

  roptions -> AddStringOption3 ("milp_solver",
				"Choose the subsolver to solve MILP sub-problems in OA decompositions.",
				"Cbc_D",
				"Cbc_D","Coin Branch and Cut with its default",
				"Cbc_Par", "Coin Branch and Cut with passed parameters",
				"Cplex","Cplex",
				" To use Cplex, a valid license is required and you should have compiled OsiCpx in COIN-OR  (see Osi documentation).");

  roptions -> setOptionExtraInfo ("milp_solver",64);

  roptions -> AddStringOption2 ("milp_strategy",
				"Choose a strategy for MILPs.",
				"find_good_sol",
				"find_good_sol","Stop sub milps when a solution improving the incumbent is found",
				"solve_to_optimality", "Solve MILPs to optimality",
				"");

  roptions -> AddStringOption6 ("algorithm",
				"Choice of the algorithm.",
				"B-BB",
				"B-BB","simple branch-and-bound algorithm,",
				"B-OA","OA Decomposition algorithm,",
				"B-QG","Quesada and Grossmann branch-and-cut algorithm,",
				"B-Hyb","hybrid outer approximation based branch-and-cut,",
				"B-Ecp","ecp cuts based branch-and-cut a la FilMINT.",
				"B-iFP","Iterated Feasibility Pump for MINLP.",
				"This will preset some of the options of bonmin depending on the algorithm choice."
				);

  CouenneProblem          ::registerOptions (roptions);
  CouenneCutGenerator     ::registerOptions (roptions);
  CouenneChooseStrong     ::registerOptions (roptions);
  CouenneChooseVariable   ::registerOptions (roptions);
  CouenneFixPoint         ::registerOptions (roptions);
  CouenneDisjCuts         ::registerOptions (roptions);
  CouenneCrossConv        ::registerOptions (roptions);
  CouenneSdpCuts          ::registerOptions (roptions);
  CouenneTwoImplied       ::registerOptions (roptions);
  NlpSolveHeuristic       ::registerOptions (roptions);
  CouenneFeasPump         ::registerOptions (roptions);
  CouenneIterativeRounding::registerOptions (roptions);

  /// TODO: move later!
  roptions -> AddStringOption2
    ("local_branching_heuristic",
     "Apply local branching heuristic",
     "no",
     "no","",
     "yes","",
     "A local-branching heuristic based is used to find feasible solutions.");


  roptions -> AddNumberOption  ("couenne_check",
				"known value of a global optimum (for debug purposes only)",
				COIN_DBL_MAX,
				"Default value is +infinity.");

  roptions -> AddStringOption2 ("display_stats",
				"display statistics at the end of the run",
				"no",
				"yes", "",
				"no", "");

  roptions -> AddStringOption2 ("save_soltext",
				"save pairs (index, value) of the solution at the end of the solve",
				"no",
				"yes", "",
				"no", "");

  roptions -> AddStringOption2 ("test_mode",
				"set to true if this is Couenne unit test",
				"no",
				"yes", "",
				"no", "");

  roptions -> AddStringOption5 ("lp_solver",
				"Linear Programming solver for the linearization",
				"clp",
				"clp",    "Use the COIN-OR Open Source solver CLP (default)",
				"cplex",  "Use the commercial solver Cplex (license is needed)",
				"gurobi", "Use the commercial solver Gurobi (license is needed)",
				"soplex", "Use the freely available Soplex",
                                "xpress-mp", "Use the commercial solver Xpress MP (license is needed)"
				);

#define addLevOption(optname,comment,default) roptions -> AddBoundedIntegerOption (optname, comment, -2, J_LAST_LEVEL-1, default, "")

  addLevOption ("output_level",                "Output level",                                          J_WARNING);
  addLevOption ("branching_print_level",       "Output level for braching code in Couenne",             J_NONE);
  addLevOption ("boundtightening_print_level", "Output level for bound tightening code in Couenne",     J_NONE);
  addLevOption ("convexifying_print_level",    "Output level for convexifying code in Couenne",         J_NONE);
  addLevOption ("problem_print_level",         "Output level for problem manipulation code in Couenne", J_NONE);
  addLevOption ("nlpheur_print_level",         "Output level for NLP heuristic in Couenne",             J_NONE);
  addLevOption ("disjcuts_print_level",        "Output level for disjunctive cuts in Couenne",          J_NONE);
  addLevOption ("reformulate_print_level",     "Output level for reformulating problems in Couenne",    J_NONE);

  roptions -> AddNumberOption
    ("feas_tolerance",
     "Tolerance for constraints/auxiliary variables",
     feas_tolerance_default,
     "Default value is 1e-5.");

  roptions -> AddStringOption2 
    ("feasibility_bt",
     "Feasibility-based (cheap) bound tightening (FBBT)",
     "yes",
     "no","",
     "yes","",
     "A pre-processing technique to reduce the bounding box, before the generation of linearization cuts. "
     "This is a quick and effective way to reduce the solution set, and it is highly recommended to keep it active."
    );

  // copied from BonminSetup::registerMilpCutGenerators(), in
  // BonBonminSetup.cpp

  struct cutOption_ {

    const char *cgname;
    int         defaultFreq;

  } cutOption [] = {
    {(const char *) "Gomory_cuts",             0},
    {(const char *) "probing_cuts",            0},
    {(const char *) "cover_cuts",              0},
    {(const char *) "mir_cuts",                0},
    {(const char *) "2mir_cuts",               0},
    {(const char *) "flow_covers_cuts",        0},
    {(const char *) "lift_and_project_cuts",   0},
    {(const char *) "reduce_split_cuts",       0},
    {(const char *) "clique_cuts",             0},
    {NULL, 0}};

  for (int i=0; cutOption [i].cgname; i++) {

    char descr [150];

    sprintf (descr, "Frequency k (in terms of nodes) for generating %s cuts in branch-and-cut.",
	     cutOption [i].cgname);

    roptions -> AddLowerBoundedIntegerOption 
      (cutOption [i].cgname,
       descr,
       -100, cutOption [i].defaultFreq,
       "If k > 0, cuts are generated every k nodes, "
       "if -99 < k < 0 cuts are generated every -k nodes but "
       "Cbc may decide to stop generating cuts, if not enough are generated at the root node, "
       "if k=-99 generate cuts only at the root node, if k=0 or 100 do not generate cuts.");

    roptions->setOptionExtraInfo (cutOption [i].cgname, 5);
  }
}