Exemple #1
0
void
ProblemsReader::readConstraint(Problem& problem, unsigned int /*i*/) {

	LinearConstraint constraint;

	double       value;
	char         rel[2];
	unsigned int numVariables;

	*_stream >> value >> rel >> numVariables;

	Relation relation;
	if (rel[0] == '<')
		relation = GreaterEqual; // switch relation, since in file: value rel term
	else if (rel[0] == '>')
		relation = LessEqual; // switch relation, since in file: value rel term
	else
		relation = Equal;

	constraint.setRelation(relation);
	constraint.setValue(value);

	for (unsigned int j = 0; j < numVariables; j++) {

		int id;
		*_stream >> id;

		if (id >= 0) {

			unsigned int varNum = problem.getConfiguration()->getVariable(id);
			constraint.setCoefficient(varNum, 1.0);

		} else {

			unsigned int varNum = problem.getConfiguration()->getVariable(-id);
			constraint.setCoefficient(varNum, -1.0);
		}
	}

	problem.getLinearConstraints()->add(constraint);

	LOG_ALL(streamproblemreaderlog) << "found constraint " << constraint << std::endl;
}
Exemple #2
0
void
ProblemsReader::readVariable(Problem& problem, unsigned int i) {

	unsigned int id;
	float costs;

	*_stream >> id;
	*_stream >> costs;

	LOG_ALL(streamproblemreaderlog) << "found variable " << i << " (id " << id << ") with costs " << costs << std::endl;

	// set costs in objective
	problem.getObjective()->setCoefficient(i, costs);

	// remember mapping from id to variable num
	problem.getConfiguration()->setVariable(id, i);
}