revert AddName(), add IntExpr::VarWithName()
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user