当前位置: 首页>>代码示例>>C++>>正文


C++ Constraint::constant方法代码示例

本文整理汇总了C++中Constraint::constant方法的典型用法代码示例。如果您正苦于以下问题:C++ Constraint::constant方法的具体用法?C++ Constraint::constant怎么用?C++ Constraint::constant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Constraint的用法示例。


在下文中一共展示了Constraint::constant方法的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";
}
开发者ID:t-crest,项目名称:patmos-otawa,代码行数:28,代码来源:lp_solve5.cpp

示例2: solve

// 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),
//.........这里部分代码省略.........
开发者ID:t-crest,项目名称:patmos-otawa,代码行数:101,代码来源:lp_solve5.cpp


注:本文中的Constraint::constant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。