本文整理汇总了C++中Constraint::comparator方法的典型用法代码示例。如果您正苦于以下问题:C++ Constraint::comparator方法的具体用法?C++ Constraint::comparator怎么用?C++ Constraint::comparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Constraint
的用法示例。
在下文中一共展示了Constraint::comparator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportLP
void System::exportLP(io::Output& out) {
static CString texts[] = { "<", "<=", "=", ">=", ">" };
out << "/* IPET system */\n";
// Output the objective function
if(ofun->comparator() >= 0)
out << "max: ";
else
out << "min: ";
ofun->dump(out);
out << ";\n";
// Output the constraints
for(Constraint *cons = conss; cons; cons = cons->next()) {
cons->dump(out);
out << " " << texts[cons->comparator() + 2]
<< " " << (int)cons->constant() << ";";
const string& label = cons->label();
if(label)
out << "\t/* " << label << "*/";
out << io::endl;
}
// Output int constraints
for(genstruct::HashTable<ilp::Var *, Var *>::Iterator var(vars);
var; var++)
out << "int " << var->makeVarName() << ";\n";
}
示例2: make_lp
// Overload
bool System::solve(WorkSpace *ws) {
static short comps[] = { LE, LE, EQ, GE, GE };
static double corr[] = { -1, 0, 0, 0, +1 };
// allocate and initialize the lp_solve data structure
lprec *lp = make_lp(0, cols);
set_verbose(lp, IMPORTANT);
REAL row[cols + 1];
for(int i = 1; i <= cols; i++)
row[i] = 0;
//set_int(lp, i, TRUE);
// set the type of variable
for(var_map_t::Iterator var(vars); var; var++) {
switch(var->variable()->type()) {
case ilp::Var::INT: set_int(lp, var->column(), TRUE); break;
case ilp::Var::BIN: set_binary(lp, var->column(), TRUE); break;
case ilp::Var::FLOAT: break;
default: ASSERT(false); break;
}
set_col_name(lp, var->column(), (char*)var->variable()->name().chars());
}
// Build the object function
ofun->fillRow(row);
row[0] = 0;
set_obj_fn(lp, row);
ofun->resetRow(row);
if(ofun->comparator() >= 0)
set_maxim(lp);
else
set_minim(lp);
// Build the matrix
for(Constraint *cons = conss; cons; cons = cons->next()) {
cons->fillRow(row);
Constraint::comparator_t comp = cons->comparator();
double cst = cons->constant();
add_constraint(lp, row,
comps[comp - Constraint::LT],
cst + corr[comp - Constraint::LT]);
/*cout << "=> ";
for(int i = 0; i <= cols; i++)
cout << row[i] << '\t';
cout << io::endl;*/
cons->resetRow(row);
}
// if required, record the cancellation test
if(ws)
put_abortfunc(lp, test_cancellation, ws);
// Launch the resolution
if (!ILPNAME(ws).get().isEmpty()) {
Path p(ILPNAME(ws));
write_lp(lp, (char*)p.toString().chars());
}
int fail = ::solve(lp);
// Record the result
int result = false;
if(!ws || !ws->isCancelled()) {
if(fail == OPTIMAL) {
result = true;
// Record variables values
for(elm::genstruct::HashTable<ilp::Var *, Var *>::Iterator var(vars);
var; var++)
var->setValue((double)lp->best_solution[lp->rows + var->column()]);
// Get optimization result
//cout << "=> " << get_objective(lp) << " <=> " << int(get_objective(lp)) << "<=\n";
val = rint(get_objective(lp));
}
// !!DEBUG!!
else {
// messages
# define ERRORM(x) { x, #x }
static struct {
int code;
cstring msg;
} msgs[] = {
ERRORM(UNKNOWNERROR),
ERRORM(DATAIGNORED),
ERRORM(NOBFP),
ERRORM(NOMEMORY),
ERRORM(NOTRUN),
ERRORM(OPTIMAL),
ERRORM(SUBOPTIMAL),
ERRORM(INFEASIBLE),
ERRORM(UNBOUNDED),
ERRORM(DEGENERATE),
ERRORM(NUMFAILURE),
ERRORM(USERABORT),
ERRORM(TIMEOUT),
ERRORM(RUNNING),
//.........这里部分代码省略.........