本文整理汇总了C++中ModelPtr::getVars方法的典型用法代码示例。如果您正苦于以下问题:C++ ModelPtr::getVars方法的具体用法?C++ ModelPtr::getVars怎么用?C++ ModelPtr::getVars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelPtr
的用法示例。
在下文中一共展示了ModelPtr::getVars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createModel
TEST(solver_interface, setup_problem) {
ModelPtr solver = createModel(SOLVER_GUROBI);
vector<Var> vars;
for (int i=0; i < 3; ++i) {
char namebuf[5];
sprintf(namebuf, "v%i", i);
vars.push_back(solver->addVar(namebuf));
}
solver->update();
AffExpr aff;
cout << aff << endl;
for (int i=0; i < 3; ++i) {
exprInc(aff, vars[i]);
solver->setVarBounds(vars[i], 0, 10);
}
aff.constant -= 3;
cout << aff << endl;
QuadExpr affsquared = exprSquare(aff);
solver->setObjective(affsquared);
solver->update();
LOG_INFO("objective: %s", CSTR(affsquared));
LOG_INFO("please manually check that /tmp/solver-interface-test.lp matches this");
solver->writeToFile("/tmp/solver-interface-test.lp");
solver->optimize();
vector<double> soln(3);
for (int i=0; i < 3; ++i) {
soln[i] = solver->getVarValue(vars[i]);
}
EXPECT_NEAR(aff.value(soln), 0, 1e-6);
solver->removeVar(vars[2]);
solver->update();
EXPECT_EQ(solver->getVars().size(), 2);
}