revert AddName(), add IntExpr::VarWithName()

This commit is contained in:
lperron@google.com
2012-01-21 16:20:55 +00:00
parent a1ec8febfe
commit afc964f50d
3 changed files with 9 additions and 7 deletions

View File

@@ -3657,6 +3657,10 @@ class IntExpr : public PropagationBaseObject {
// Creates a variable from the expression.
virtual IntVar* Var() = 0;
// Creates a variable from the expression and set the name of the
// resulting var.
IntVar* VarWithName(const string& name);
// Attach a demon that will watch the min or the max of the expression.
virtual void WhenRange(Demon* d) = 0;
@@ -3718,9 +3722,6 @@ class IntVar : public IntExpr {
virtual bool IsVar() const { return true; }
virtual IntVar* Var() { return this; }
// Name the current variable and returns the variable.
// This method is useful after a Var() call.
IntVar* AddName(const string& name);
// This method returns the value of the variable. This method checks
// before that the variable is bound.

View File

@@ -49,9 +49,10 @@ IntVar::IntVar(Solver* const s, const string& name) : IntExpr(s) {
set_name(name);
}
IntVar* IntVar::AddName(const string& name) {
set_name(name);
return this;
IntVar* IntExpr::VarWithName(const string& name) {
IntVar* const var = Var();
var->set_name(name);
return var;
}
namespace {

View File

@@ -360,7 +360,7 @@ void SportsScheduling(int num_teams) {
// Objective.
IntVar* const objective_var =
solver.MakeSum(team_breaks)->Var()->AddName("SumOfBreaks");
solver.MakeSum(team_breaks)->VarWithName("SumOfBreaks");
OptimizeVar* const objective_monitor = solver.MakeMinimize(objective_var, 1);
monitors.push_back(objective_monitor);