本文整理汇总了C++中IloEnv::out方法的典型用法代码示例。如果您正苦于以下问题:C++ IloEnv::out方法的具体用法?C++ IloEnv::out怎么用?C++ IloEnv::out使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IloEnv
的用法示例。
在下文中一共展示了IloEnv::out方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: model
int
main (void) {
IloEnv env;
try {
IloModel model(env);
IloNumVarArray var(env);
IloRangeArray con(env);
populatebyrow (model, var, con);
IloCplex cplex(model);
cplex.solve();
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, con);
env.out() << "Slacks = " << vals << endl;
cplex.exportModel("mipex1.lp");
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例2: main
ILOSTLBEGIN
//typedef IloArray<IloNumArray> TwoDMatrix;
int main(int argc, char **argv)
{
IloEnv env;
try
{
IloNumVar X(env, 0, IloInfinity, ILOFLOAT);
IloNum X_val;
IloNumVar Y(env, 0, 10, ILOINT);
IloNum Y_val;
IloModel model(env);
IloExpr Obj(env);
Obj = 5*X - 3*Y;
model.add(IloMinimize(env,Obj)); // IloMinimize is used for minimization problems
//Alternatively, model.add(IloMinimize(env,Obj)); can be replaced by the following three lines.
//This is useful while iterating in Decomposition Techniques where the objective function is redefined at each iteration
//IloObjective Objective = IloMinimize(env);
//model.add(Objective);
//Objective.setExpr(Obj);
Obj.end();
model.add(X + 2*Y >= 10);
model.add(2*X - Y >= 0);
model.add(X - 3*Y >= -13);
// Optimize
IloCplex cplex(model);
//cplex.setOut(env.getNullStream()); // This is to supress the output of Branch & Bound Tree on screen
//cplex.setWarning(env.getNullStream()); //This is to supress warning messages on screen
cplex.solve();//solving the MODEL
if (cplex.getStatus() == IloAlgorithm::Infeasible) // if the problem is infeasible
{
env.out() << "Problem Infeasible" << endl;
}
X_val = cplex.getValue(X);
Y_val = cplex.getValue(Y);
// Print results
cout<< "Objective Value = " << cplex.getObjValue() << endl;
cout<<"X = "<<X_val<<endl;
cout<<"Y = "<<Y_val<<endl;
}
catch(IloException &e)
{
env.out() << "ERROR: " << e << endl;
}
catch(...)
{
env.out() << "Unknown exception" << endl;
}
env.end();
return 0;
}
示例3: model
int
main (int argc, char **argv)
{
char const *vmconfig = NULL;
// Check command line length (exactly two arguments are required).
if ( argc != 3 ) {
usage (argv[0]);
return -1;
}
// Pick up VMC from command line.
vmconfig = argv[1];
// Solve the model.
int exitcode = 0;
IloEnv env;
try {
// Create and read the model.
IloModel model(env);
IloCplex cplex(model);
cplex.importModel(model, argv[2]);
// Load the virtual machine configuration.
// This will force solve() to use parallel distributed MIP.
cplex.readVMConfig(vmconfig);
// Solve the problem and display some results.
if ( cplex.solve() )
env.out() << "Solution value = " << cplex.getObjValue() << endl;
else
env.out() << "No solution" << endl;
env.out() << "Solution status = " << cplex.getStatus() << endl;
// Cleanup.
cplex.end();
model.end();
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
exitcode = -1;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
exitcode = -1;
}
env.end();
return exitcode;
} // END main
示例4: model
int
main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env, "example");
IloNumVarArray var(env);
IloRangeArray rng(env);
populatebycolumn (model, var, rng);
IloCplex cplex(model);
IloCplex::BasisStatusArray cstat(env), rstat(env);
cstat.add(IloCplex::AtUpper);
cstat.add(IloCplex::Basic);
cstat.add(IloCplex::Basic);
rstat.add(IloCplex::AtLower);
rstat.add(IloCplex::AtLower);
cplex.setBasisStatuses(cstat, var, rstat, rng);
cplex.solve();
cplex.out() << "Solution status = " << cplex.getStatus() << endl;
cplex.out() << "Solution value = " << cplex.getObjValue() << endl;
cplex.out() << "Iteration count = " << cplex.getNiterations() << endl;
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, rng);
env.out() << "Slacks = " << vals << endl;
cplex.getDuals(vals, rng);
env.out() << "Duals = " << vals << endl;
cplex.getReducedCosts(vals, var);
env.out() << "Reduced Costs = " << vals << endl;
cplex.exportModel("lpex6.lp");
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例5: main
int main(int , const char * []){
IloEnv env;
try {
IloModel model(env);
IloIntVar Belgium(env, 0, 3), Denmark(env, 0, 3),
France(env, 0, 3), Germany(env, 0, 3),
Luxembourg(env, 0, 3), Netherlands(env, 0, 3);
model.add(Belgium != France);
model.add(Belgium != Germany);
model.add(Belgium != Netherlands);
model.add(Belgium != Luxembourg);
model.add(Denmark == Germany);
model.add(France != Germany);
model.add(France != Luxembourg);
model.add(Germany != Luxembourg);
model.add(Germany != Netherlands);
IloCP cp(model);
cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet);
if (cp.solve()){
cp.out() << std::endl << cp.getStatus() << " Solution" << std::endl;
cp.out() << "Belgium: " << Names[cp.getValue(Belgium)] << std::endl;
cp.out() << "Denmark: " << Names[cp.getValue(Denmark)] << std::endl;
cp.out() << "France: " << Names[cp.getValue(France)] << std::endl;
cp.out() << "Germany: " << Names[cp.getValue(Germany)] << std::endl;
cp.out() << "Luxembourg: " << Names[cp.getValue(Luxembourg)] << std::endl;
cp.out() << "Netherlands: " << Names[cp.getValue(Netherlands)] << std::endl;
}
}
catch (IloException& ex) {
env.out() << "Error: " << ex << std::endl;
}
env.end();
return 0;
}
示例6: model
int
main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env);
IloCplex cplex(env);
if ( argc != 2 ) {
usage (argv[0]);
throw(-1);
}
IloObjective obj;
IloNumVarArray var(env);
IloRangeArray rng(env);
IloSOS1Array sos1(env);
IloSOS2Array sos2(env);
IloRangeArray lazy(env);
IloRangeArray cuts(env);
cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts);
cplex.extract(model);
if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy);
if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts);
cplex.solve();
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例7: main
int main(int, const char * []) {
IloEnv env;
try {
IloIntVarArray x(env);
for (IloInt i = 0; i < 10; i++) {
char name[6];
sprintf(name, "X%ld", i);
x.add(IloIntVar(env, 0, 100 - 2*(i / 2), name));
}
IloModel mdl(env);
mdl.add(IloAllDiff(env, x));
mdl.add(x);
IloIntVarChooser varChooser = ChooseSmallestCentroid(env);
IloIntValueChooser valChooser = ChooseSmallestDistanceFromCentroid(env);
IloSearchPhase sp1(env, x, varChooser, valChooser);
IloIntVarEval varEval = Centroid(env);
IloIntValueEval valEval = DistanceFromCentroid(env);
IloSearchPhase sp2(env, x, IloSelectSmallest(varEval),
IloSelectSmallest(valEval));
// sp2 can have ties as two variable or values could evaluate
// to the same values. sp3 shows how to break these ties
// choosing, for equivalent centroid and distance-to-centroid
// evaluations, the lowest indexed variable in x and the
// lowest value.
IloVarSelectorArray selVar(env);
selVar.add(IloSelectSmallest(varEval));
selVar.add(IloSelectSmallest(IloVarIndex(env, x))); // break ties on index
IloValueSelectorArray selValue(env);
selValue.add(IloSelectSmallest(valEval));
selValue.add(IloSelectSmallest(IloValue(env))); // break ties on smallest
IloSearchPhase sp3(env, x, selVar, selValue);
IloCP cp(mdl);
cp.setParameter(IloCP::Workers, 1);
cp.setParameter(IloCP::SearchType, IloCP::DepthFirst);
cp.setParameter(IloCP::LogPeriod, 1);
cp.out() << "Choosers" << std::endl;
cp.solve(sp1);
cp.out() << cp.domain(x) << std::endl;
cp.out() << "Evaluators" << std::endl;
cp.solve(sp2);
cp.out() << cp.domain(x) << std::endl;
cp.out() << "Evaluators (with tie-break)" << std::endl;
cp.solve(sp3);
cp.out() << cp.domain(x) << std::endl;
cp.end();
} catch (IloException & ex) {
env.out() << "Caught: " << ex << std::endl;
}
env.end();
return 0;
}
示例8: model
int
main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env);
IloCplex cplex(env);
if ( argc != 2 ) {
usage (argv[0]);
throw(-1);
}
IloObjective obj;
IloNumVarArray var(env);
IloRangeArray rng(env);
cplex.importModel(model, argv[1], obj, var, rng);
cplex.use(Rounddown(env, var));
cplex.extract(model);
// Check model is all binary except for objective constant variable
if ( cplex.getNbinVars() < cplex.getNcols() - 1 ) {
cerr << "Problem contains non-binary variables, exiting." << endl;
throw (-1);
}
cplex.setParam(IloCplex::Param::MIP::Strategy::Search,
IloCplex::Traditional);
cplex.solve();
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
env.out() << "Values = " << vals << endl;
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例9: m
int
main(int argc, char** argv)
{
IloEnv env;
try {
IloModel m(env);
IloCplex cplex(env);
IloObjective obj;
IloNumVarArray vars(env);
IloRangeArray rngs(env);
const char* datadir = (argc >= 2) ? argv[1] : "../../../examples/data";
char *fname = new char[strlen(datadir) + 1 + strlen("noswot.mps") + 1];
sprintf(fname, "%s/noswot.mps", datadir);
env.out() << "reading " << fname << endl;
cplex.importModel(m, fname, obj, vars, rngs);
delete[] fname;
env.out() << "extracting model ..." << endl;
cplex.extract(m);
IloRangeArray cuts(env);
makeCuts(cuts, vars);
// Use addUserCuts when the added constraints strengthen the
// formulation. Use addLazyConstraints when the added constraints
// remove part of the feasible region. Use addCuts when you are
// not certain.
cplex.addUserCuts(cuts);
cuts.endElements();
cuts.end();
cplex.setParam(IloCplex::Param::MIP::Interval, 1000);
env.out() << "solving model ...\n";
cplex.solve();
env.out() << "solution status is " << cplex.getStatus() << endl;
env.out() << "solution value is " << cplex.getObjValue() << endl;
}
catch (IloException& ex) {
cerr << "Error: " << ex << endl;
}
env.end();
return 0;
}
示例10: model
int
main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env);
IloNumVarArray var(env);
IloRangeArray con(env);
populatebyrow (model, var, con);
IloCplex cplex(model);
// Optimize the problem and obtain solution.
if ( !cplex.solve() ) {
env.error() << "Failed to optimize LP" << endl;
throw(-1);
}
IloNumArray vals(env);
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, con);
env.out() << "Slacks = " << vals << endl;
cplex.getDuals(vals, con);
env.out() << "Duals = " << vals << endl;
cplex.getReducedCosts(vals, var);
env.out() << "Reduced Costs = " << vals << endl;
cplex.exportModel("qpex1.lp");
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例11: m
int
main(int argc, char** argv)
{
IloEnv env;
try {
IloModel m(env);
IloCplex cplex(env);
IloObjective obj;
IloNumVarArray var(env);
IloRangeArray con(env);
const char* datadir = (argc >= 2) ? argv[1] : "../../../examples/data";
char *fname = new char[strlen(datadir) + 1 + strlen("noswot.mps") + 1];
sprintf(fname, "%s/noswot.mps", datadir);
env.out() << "reading " << fname << endl;
cplex.importModel(m, fname, obj, var, con);
delete[] fname;
env.out() << "constructing cut callback ..." << endl;
IloExprArray lhs(env);
IloNumArray rhs(env);
makeCuts(var, lhs, rhs);
cplex.use(CtCallback(env, lhs, rhs, cplex.getParam(
IloCplex::Param::Simplex::Tolerances::Feasibility)));
env.out() << "extracting model ..." << endl;
cplex.extract(m);
cplex.setParam(IloCplex::Param::MIP::Interval, 1000);
cplex.setParam(IloCplex::Param::MIP::Strategy::Search,
IloCplex::Traditional);
env.out() << "solving model ...\n";
cplex.solve();
env.out() << "solution status is " << cplex.getStatus() << endl;
env.out() << "solution value is " << cplex.getObjValue() << endl;
}
catch (IloException& ex) {
cerr << "Error: " << ex << endl;
}
env.end();
return 0;
}
示例12: main
int main(int argc, const char* argv[]){
IloEnv env;
try {
const char* filename = "../../../examples/data/sched_conflict.data";
IloInt failLimit = 10000;
if (argc > 1)
filename = argv[1];
if (argc > 2)
failLimit = atoi(argv[2]);
IloConstraintArray allCts(env);
IloConstraintArray capacityCts(env);
IloConstraintArray precedenceCts(env);
IloModel model = ReadModel(env, filename, capacityCts, precedenceCts);
allCts.add(capacityCts);
allCts.add(precedenceCts);
IloCP cp(model);
cp.setParameter(IloCP::FailLimit, failLimit);
cp.setParameter(IloCP::CumulFunctionInferenceLevel, IloCP::Extended);
cp.setParameter(IloCP::ConflictRefinerOnVariables, IloCP::On);
cp.out() << "Instance \t: " << filename << std::endl;
if (cp.solve()) {
// A solution was found
cp.out() << "Solution found with makespan : " << cp.getObjValue() << std::endl;
} else {
IloInt status = cp.getInfo(IloCP::FailStatus);
if (status != IloCP::SearchHasFailedNormally) {
// No solution found but problem was not proved infeasible
cp.out() << "No solution found but problem was not proved infeasible." << std::endl;
} else {
// Run conflict refiner only if problem was proved infeasible
cp.out() << "Infeasible problem, running conflict refiner ..." << std::endl;
cp.out() << std::endl;
cp.out() << "SCENARIO 1: Basic conflict refiner:" << std::endl;
cp.out() << std::endl;
runBasicConflictRefiner(cp);
cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet);
cp.out() << "SCENARIO 2: Conflict refiner with preference on resource capacity constraints:" << std::endl;
cp.out() << std::endl;
runConflictRefinerWithPreferences(cp, capacityCts, precedenceCts);
cp.out() << "SCENARIO 3: Conflict refiner with preference on precedence constraints:" << std::endl;
cp.out() << std::endl;
runConflictRefinerWithPreferences(cp, precedenceCts, capacityCts);
cp.out() << "SCENARIO 4: Conflict partition:" << std::endl;
cp.out() << std::endl;
runConflictRefinerPartition(cp, allCts);
cp.out() << "SCENARIO 5: All conflicts:" << std::endl;
cp.out() << std::endl;
runConflictRefinerAllConflicts(cp, allCts);
}
}
} catch (IloException& ex) {
env.out() << "Caught: " << ex << std::endl;
}
env.end();
return 0;
}
示例13: model
int
main (void) {
IloEnv env;
try {
IloModel model(env);
IloNumVarArray var(env);
IloRangeArray con(env);
populatebyrow (model, var, con);
IloCplex cplex(model);
IloNumVarArray ordvar(env, 2);
IloNumArray ordpri(env, 2);
ordvar[0] = var[1]; ordvar[1] = var[3];
ordpri[0] = 8.0; ordpri[1] = 7.0;
cplex.setPriorities (ordvar, ordpri);
cplex.setDirection(var[1], IloCplex::BranchUp);
cplex.setDirection(var[3], IloCplex::BranchDown);
cplex.solve();
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, con);
env.out() << "Slacks = " << vals << endl;
cplex.exportModel("mipex3.lp");
cplex.writeOrder("mipex3.ord");
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例14: model
int
main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env);
IloCplex cplex(env);
if ( argc != 2 ) {
usage (argv[0]);
throw(-1);
}
IloObjective obj;
IloNumVarArray var(env);
IloRangeArray rng(env);
IloSOS1Array sos1(env);
IloSOS2Array sos2(env);
cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2);
cplex.use(SOSbranch(env, sos1));
cplex.setParam(IloCplex::Param::MIP::Strategy::Search,
IloCplex::Traditional);
cplex.extract(model);
cplex.solve();
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
env.out() << "Values = " << vals << endl;
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
示例15: model
int
main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env, "example");
IloNumVarArray var(env);
IloRangeArray rng(env);
populatebycolumn (model, var, rng);
IloCplex cplex(model);
cplex.setOut(env.getNullStream());
cplex.setParam(IloCplex::Param::RootAlgorithm, IloCplex::Primal);
cplex.use(MyCallback(env));
cplex.solve();
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
IloNumArray vals(env);
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, rng);
env.out() << "Slacks = " << vals << endl;
cplex.getDuals(vals, rng);
env.out() << "Duals = " << vals << endl;
cplex.getReducedCosts(vals, var);
env.out() << "Reduced Costs = " << vals << endl;
cplex.exportModel("lpex4.lp");
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main