diff --git a/ortools/linear_solver/samples/CloneModelMb.java b/ortools/linear_solver/samples/CloneModelMb.java index b1445374f6..295875714c 100644 --- a/ortools/linear_solver/samples/CloneModelMb.java +++ b/ortools/linear_solver/samples/CloneModelMb.java @@ -55,22 +55,24 @@ public final class CloneModelMb { model.maximize(LinearExpr.newBuilder().add(x).addTerm(y, 10.0)); // [END objective] - // Deep copy + // [Start clone] + // Clone the model. System.out.println("Cloning the model"); - ModelBuilder modelCopy = model.clone(); + ModelBuilder modelCopy = model.getClone(); Variable xCopy = modelCopy.varFromIndex(x.getIndex()); Variable yCopy = modelCopy.varFromIndex(y.getIndex()); Variable zCopy = modelCopy.newBoolVar("z"); LinearConstraint c2Copy = modelCopy.constraintFromIndex(c2.getIndex()); - // Add new constraint. - LinearConstraint c3Copy = modelCopy.addGreaterOrEqual(xCopy, 1); + // Add a new constraint. + LinearConstraint unusedC3Copy = modelCopy.addGreaterOrEqual(xCopy, 1); // Modify a constraint. c2Copy.addTerm(zCopy, 2.0); System.out.println("Number of constraints in the original model = " + model.numConstraints()); System.out.println("Number of constraints in the cloned model = " + modelCopy.numConstraints()); + // [END clone] // [START solve] // Solve with the SCIP MIP solver. diff --git a/ortools/linear_solver/samples/clone_model_mb.py b/ortools/linear_solver/samples/clone_model_mb.py index e8c02c8ea9..acc99f9fbe 100644 --- a/ortools/linear_solver/samples/clone_model_mb.py +++ b/ortools/linear_solver/samples/clone_model_mb.py @@ -46,7 +46,8 @@ def main(): model.maximize(x + 10 * y) # [END objective] - # Deep copy. + # [Start clone] + # Clone the model. print("Cloning the model.") model_copy = model.clone() x_copy = model_copy.var_from_index(x.index) @@ -61,6 +62,7 @@ def main(): # Modify a constraint. c2_copy.add_term(z_copy, 2.0) + # [END clone] # [START solve] # Create the solver with the SCIP backend, and solve the model.