sync formating between google and github
This commit is contained in:
@@ -1187,10 +1187,10 @@ class Solver {
|
||||
IntExpr* MakeSemiContinuousExpr(IntExpr* const expr, int64 fixed_charge,
|
||||
int64 step);
|
||||
|
||||
/// General piecewise-linear function expression, built from f(x) where f is
|
||||
/// piecewise-linear. The resulting expression is f(expr).
|
||||
// TODO(user): Investigate if we can merge all three piecewise linear
|
||||
/// expressions.
|
||||
/// General piecewise-linear function expression, built from f(x) where f is
|
||||
/// piecewise-linear. The resulting expression is f(expr).
|
||||
// TODO(user): Investigate if we can merge all three piecewise linear
|
||||
/// expressions.
|
||||
#ifndef SWIG
|
||||
IntExpr* MakePiecewiseLinearExpr(IntExpr* expr,
|
||||
const PiecewiseLinearFunction& f);
|
||||
@@ -1377,7 +1377,7 @@ class Solver {
|
||||
/// Creates a demon from a callback.
|
||||
Demon* MakeActionDemon(Action action);
|
||||
#endif /// !defined(SWIG)
|
||||
/// Creates a demon from a closure.
|
||||
/// Creates a demon from a closure.
|
||||
Demon* MakeClosureDemon(Closure closure);
|
||||
|
||||
// ----- Between and related constraints -----
|
||||
@@ -2864,7 +2864,7 @@ class Solver {
|
||||
|
||||
Decision* balancing_decision() const { return balancing_decision_.get(); }
|
||||
|
||||
/// Internal
|
||||
/// Internal
|
||||
#if !defined(SWIG)
|
||||
void set_fail_intercept(std::function<void()> fail_intercept) {
|
||||
fail_intercept_ = std::move(fail_intercept);
|
||||
|
||||
@@ -1525,7 +1525,7 @@ class PathOperator : public IntVarLocalSearchOperator {
|
||||
}
|
||||
}
|
||||
#endif // SWIG
|
||||
/// Returns the active node in the given alternative set.
|
||||
/// Returns the active node in the given alternative set.
|
||||
int64 GetActiveInAlternativeSet(int alternative_index) const {
|
||||
return alternative_index >= 0
|
||||
? active_in_alternative_set_[alternative_index]
|
||||
@@ -1597,7 +1597,7 @@ class PathOperator : public IntVarLocalSearchOperator {
|
||||
bool optimal_paths_enabled_;
|
||||
std::vector<int> path_basis_;
|
||||
std::vector<bool> optimal_paths_;
|
||||
/// Node alternative data.
|
||||
/// Node alternative data.
|
||||
#ifndef SWIG
|
||||
std::vector<std::vector<int64> > alternative_sets_;
|
||||
#endif // SWIG
|
||||
|
||||
@@ -278,7 +278,7 @@ class Deviation : public Constraint {
|
||||
if (greedy_sum == scaled_total_sum) { // No repair needed.
|
||||
ComputeMaxWhenNoRepair();
|
||||
} else { // Repair and compute maximums.
|
||||
// Try to repair the sum greedily.
|
||||
// Try to repair the sum greedily.
|
||||
if (CanPushSumAcrossMean(greedy_sum, scaled_total_sum)) {
|
||||
const int64 delta = greedy_sum > scaled_total_sum ? -size_ : size_;
|
||||
for (int j = 0; j < overlaps_.size() && greedy_sum != scaled_total_sum;
|
||||
|
||||
@@ -1132,7 +1132,7 @@ class SmallMaxConstraint : public Constraint {
|
||||
const int64 var_max = var->Max();
|
||||
if ((old_max == computed_max_.Value() && old_max != var_max) ||
|
||||
var_min > computed_min_.Value()) { // REWRITE
|
||||
// Can influence the min var bounds.
|
||||
// Can influence the min var bounds.
|
||||
int64 max_min = kint64min;
|
||||
int64 max_max = kint64min;
|
||||
for (IntVar* const var : vars_) {
|
||||
|
||||
@@ -11,18 +11,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// """From Bradley, Hax, and Magnanti, 'Applied Mathematical Programming',
|
||||
// figure 8.1.""" [START program]
|
||||
// """From Bradley, Hax, and Magnanti, 'Applied Mathematical Programming', figure 8.1."""
|
||||
// [START program]
|
||||
using System;
|
||||
using Google.OrTools.Graph;
|
||||
|
||||
public class SimpleMinCostFlowProgram {
|
||||
static void Main() {
|
||||
// [START data]
|
||||
// Define four parallel arrays: sources, destinations, capacities, and unit
|
||||
// costs between each pair. For instance, the arc from node 0 to node 1 has
|
||||
// a capacity of 15. Problem taken From Taha's 'Introduction to Operations
|
||||
// Research', example 6.4-2.
|
||||
// Define four parallel arrays: sources, destinations, capacities, and unit costs
|
||||
// between each pair. For instance, the arc from node 0 to node 1 has a
|
||||
// capacity of 15.
|
||||
// Problem taken From Taha's 'Introduction to Operations Research',
|
||||
// example 6.4-2.
|
||||
int[] startNodes = { 0, 0, 1, 1, 1, 2, 2, 3, 4 };
|
||||
int[] endNodes = { 1, 2, 2, 3, 4, 3, 4, 4, 2 };
|
||||
int[] capacities = { 15, 8, 20, 4, 10, 15, 4, 20, 5 };
|
||||
|
||||
@@ -122,10 +122,8 @@ public class LiteralSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class LiteralSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class LiteralSampleSat {
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
IntVar x = model.NewBoolVar("x");
|
||||
ILiteral not_x = x.Not();
|
||||
@@ -222,10 +220,8 @@ public class BoolOrSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class BoolOrSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class BoolOrSampleSat {
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
|
||||
IntVar x = model.NewBoolVar("x");
|
||||
@@ -373,10 +369,8 @@ public class ReifiedSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class ReifiedSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class ReifiedSampleSat {
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
|
||||
IntVar x = model.NewBoolVar("x");
|
||||
|
||||
@@ -254,18 +254,14 @@ using System;
|
||||
using Google.OrTools.Sat;
|
||||
using Google.OrTools.Util;
|
||||
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinter(IntVar[] variables)
|
||||
{
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinter(IntVar[] variables) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
||||
public override void OnSolutionCallback()
|
||||
{
|
||||
public override void OnSolutionCallback() {
|
||||
{
|
||||
foreach (IntVar v in variables_)
|
||||
{
|
||||
foreach (IntVar v in variables_) {
|
||||
Console.Write(String.Format("{0}={1} ", v.ShortString(), Value(v)));
|
||||
}
|
||||
Console.WriteLine();
|
||||
@@ -275,10 +271,8 @@ public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
private IntVar[] variables_;
|
||||
}
|
||||
|
||||
public class ChannelingSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class ChannelingSampleSat {
|
||||
static void Main() {
|
||||
// Create the CP-SAT model.
|
||||
CpModel model = new CpModel();
|
||||
|
||||
@@ -300,10 +294,9 @@ public class ChannelingSampleSat
|
||||
model.Add(y == 0).OnlyEnforceIf(b.Not());
|
||||
|
||||
// Search for x values in increasing order.
|
||||
model.AddDecisionStrategy(
|
||||
new IntVar[] {x},
|
||||
DecisionStrategyProto.Types.VariableSelectionStrategy.ChooseFirst,
|
||||
DecisionStrategyProto.Types.DomainReductionStrategy.SelectMinValue);
|
||||
model.AddDecisionStrategy(new IntVar[] { x },
|
||||
DecisionStrategyProto.Types.VariableSelectionStrategy.ChooseFirst,
|
||||
DecisionStrategyProto.Types.DomainReductionStrategy.SelectMinValue);
|
||||
|
||||
// Create the solver.
|
||||
CpSolver solver = new CpSolver();
|
||||
@@ -616,10 +609,8 @@ public class BinPackingProblemSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class BinPackingProblemSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class BinPackingProblemSat {
|
||||
static void Main() {
|
||||
// Data.
|
||||
int bin_capacity = 100;
|
||||
int slack_capacity = 20;
|
||||
@@ -633,51 +624,42 @@ public class BinPackingProblemSat
|
||||
|
||||
// Main variables.
|
||||
IntVar[,] x = new IntVar[num_items, num_bins];
|
||||
for (int i = 0; i < num_items; ++i)
|
||||
{
|
||||
for (int i = 0; i < num_items; ++i) {
|
||||
int num_copies = items[i, 1];
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
x[i, b] = model.NewIntVar(0, num_copies, String.Format("x_{0}_{1}", i, b));
|
||||
}
|
||||
}
|
||||
|
||||
// Load variables.
|
||||
IntVar[] load = new IntVar[num_bins];
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
load[b] = model.NewIntVar(0, bin_capacity, String.Format("load_{0}", b));
|
||||
}
|
||||
|
||||
// Slack variables.
|
||||
IntVar[] slacks = new IntVar[num_bins];
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
slacks[b] = model.NewBoolVar(String.Format("slack_{0}", b));
|
||||
}
|
||||
|
||||
// Links load and x.
|
||||
int[] sizes = new int[num_items];
|
||||
for (int i = 0; i < num_items; ++i)
|
||||
{
|
||||
for (int i = 0; i < num_items; ++i) {
|
||||
sizes[i] = items[i, 0];
|
||||
}
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
IntVar[] tmp = new IntVar[num_items];
|
||||
for (int i = 0; i < num_items; ++i)
|
||||
{
|
||||
for (int i = 0; i < num_items; ++i) {
|
||||
tmp[i] = x[i, b];
|
||||
}
|
||||
model.Add(load[b] == tmp.ScalProd(sizes));
|
||||
}
|
||||
|
||||
// Place all items.
|
||||
for (int i = 0; i < num_items; ++i)
|
||||
{
|
||||
for (int i = 0; i < num_items; ++i) {
|
||||
IntVar[] tmp = new IntVar[num_bins];
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
tmp[b] = x[i, b];
|
||||
}
|
||||
model.Add(LinearExpr.Sum(tmp) == items[i, 1]);
|
||||
@@ -685,8 +667,7 @@ public class BinPackingProblemSat
|
||||
|
||||
// Links load and slack.
|
||||
int safe_capacity = bin_capacity - slack_capacity;
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
// slack[b] => load[b] <= safe_capacity.
|
||||
model.Add(load[b] <= safe_capacity).OnlyEnforceIf(slacks[b]);
|
||||
// not(slack[b]) => load[b] > safe_capacity.
|
||||
@@ -701,26 +682,18 @@ public class BinPackingProblemSat
|
||||
CpSolverStatus status = solver.Solve(model);
|
||||
Console.WriteLine(String.Format("Solve status: {0}", status));
|
||||
if (status == CpSolverStatus.Optimal) {
|
||||
Console.WriteLine(String.Format("Optimal objective value: {0}",
|
||||
solver.ObjectiveValue));
|
||||
for (int b = 0; b < num_bins; ++b)
|
||||
{
|
||||
Console.WriteLine(String.Format("load_{0} = {1}",
|
||||
b, solver.Value(load[b])));
|
||||
for (int i = 0; i < num_items; ++i)
|
||||
{
|
||||
Console.WriteLine(string.Format(" item_{0}_{1} = {2}",
|
||||
i, b, solver.Value(x[i, b])));
|
||||
Console.WriteLine(String.Format("Optimal objective value: {0}", solver.ObjectiveValue));
|
||||
for (int b = 0; b < num_bins; ++b) {
|
||||
Console.WriteLine(String.Format("load_{0} = {1}", b, solver.Value(load[b])));
|
||||
for (int i = 0; i < num_items; ++i) {
|
||||
Console.WriteLine(string.Format(" item_{0}_{1} = {2}", i, b, solver.Value(x[i, b])));
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Statistics");
|
||||
Console.WriteLine(String.Format(" - conflicts : {0}",
|
||||
solver.NumConflicts()));
|
||||
Console.WriteLine(String.Format(" - branches : {0}",
|
||||
solver.NumBranches()));
|
||||
Console.WriteLine(String.Format(" - wall time : {0} s",
|
||||
solver.WallTime()));
|
||||
Console.WriteLine(String.Format(" - conflicts : {0}", solver.NumConflicts()));
|
||||
Console.WriteLine(String.Format(" - branches : {0}", solver.NumBranches()));
|
||||
Console.WriteLine(String.Format(" - wall time : {0} s", solver.WallTime()));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -233,7 +233,6 @@ import com.google.ortools.sat.LinearExpr;
|
||||
* pheasants are there?
|
||||
*/
|
||||
public class RabbitsAndPheasantsSat {
|
||||
|
||||
static { System.loadLibrary("jniortools"); }
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -264,10 +263,8 @@ public class RabbitsAndPheasantsSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class RabbitsAndPheasantsSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class RabbitsAndPheasantsSat {
|
||||
static void Main() {
|
||||
// Creates the model.
|
||||
CpModel model = new CpModel();
|
||||
// Creates the variables.
|
||||
@@ -582,18 +579,14 @@ using System;
|
||||
using Google.OrTools.Sat;
|
||||
using Google.OrTools.Util;
|
||||
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinter(IntVar[] variables)
|
||||
{
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinter(IntVar[] variables) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
||||
public override void OnSolutionCallback()
|
||||
{
|
||||
public override void OnSolutionCallback() {
|
||||
{
|
||||
foreach (IntVar v in variables_)
|
||||
{
|
||||
foreach (IntVar v in variables_) {
|
||||
Console.Write(String.Format("{0}={1} ", v.ShortString(), Value(v)));
|
||||
}
|
||||
Console.WriteLine();
|
||||
@@ -603,10 +596,8 @@ public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
private IntVar[] variables_;
|
||||
}
|
||||
|
||||
public class EarlinessTardinessCostSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class EarlinessTardinessCostSampleSat {
|
||||
static void Main() {
|
||||
long earliness_date = 5;
|
||||
long earliness_cost = 8;
|
||||
long lateness_date = 15;
|
||||
@@ -956,18 +947,14 @@ using System;
|
||||
using Google.OrTools.Sat;
|
||||
using Google.OrTools.Util;
|
||||
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinter(IntVar[] variables)
|
||||
{
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinter(IntVar[] variables) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
||||
public override void OnSolutionCallback()
|
||||
{
|
||||
public override void OnSolutionCallback() {
|
||||
{
|
||||
foreach (IntVar v in variables_)
|
||||
{
|
||||
foreach (IntVar v in variables_) {
|
||||
Console.Write(String.Format("{0}={1} ", v.ShortString(), Value(v)));
|
||||
}
|
||||
Console.WriteLine();
|
||||
@@ -977,10 +964,8 @@ public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
private IntVar[] variables_;
|
||||
}
|
||||
|
||||
public class StepFunctionSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class StepFunctionSampleSat {
|
||||
static void Main() {
|
||||
// Create the CP-SAT model.
|
||||
CpModel model = new CpModel();
|
||||
|
||||
|
||||
@@ -246,29 +246,23 @@ public class SolutionHintingSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinter(IntVar[] variables)
|
||||
{
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinter(IntVar[] variables) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
||||
public override void OnSolutionCallback()
|
||||
{
|
||||
public override void OnSolutionCallback() {
|
||||
{
|
||||
Console.WriteLine(String.Format("Solution #{0}: time = {1:F2} s",
|
||||
solution_count_, WallTime()));
|
||||
foreach (IntVar v in variables_)
|
||||
{
|
||||
Console.WriteLine(
|
||||
String.Format(" {0} = {1}", v.ShortString(), Value(v)));
|
||||
Console.WriteLine(
|
||||
String.Format("Solution #{0}: time = {1:F2} s", solution_count_, WallTime()));
|
||||
foreach (IntVar v in variables_) {
|
||||
Console.WriteLine(String.Format(" {0} = {1}", v.ShortString(), Value(v)));
|
||||
}
|
||||
solution_count_++;
|
||||
}
|
||||
}
|
||||
|
||||
public int SolutionCount()
|
||||
{
|
||||
public int SolutionCount() {
|
||||
return solution_count_;
|
||||
}
|
||||
|
||||
@@ -276,10 +270,8 @@ public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
private IntVar[] variables_;
|
||||
}
|
||||
|
||||
public class SolutionHintingSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class SolutionHintingSampleSat {
|
||||
static void Main() {
|
||||
// Creates the model.
|
||||
CpModel model = new CpModel();
|
||||
|
||||
@@ -304,7 +296,6 @@ public class SolutionHintingSampleSat
|
||||
VarArraySolutionPrinter cb =
|
||||
new VarArraySolutionPrinter(new IntVar[] { x, y, z });
|
||||
CpSolverStatus status = solver.SolveWithSolutionCallback(model, cb);
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -156,10 +156,8 @@ public class IntervalSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class IntervalSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class IntervalSampleSat {
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
int horizon = 100;
|
||||
IntVar start_var = model.NewIntVar(0, horizon, "start");
|
||||
@@ -286,10 +284,8 @@ public class OptionalIntervalSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class OptionalIntervalSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class OptionalIntervalSampleSat {
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
int horizon = 100;
|
||||
IntVar start_var = model.NewIntVar(0, horizon, "start");
|
||||
@@ -533,10 +529,8 @@ public class NoOverlapSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class NoOverlapSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class NoOverlapSampleSat {
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
// Three weeks.
|
||||
int horizon = 21;
|
||||
@@ -580,8 +574,7 @@ public class NoOverlapSampleSat
|
||||
CpSolver solver = new CpSolver();
|
||||
CpSolverStatus status = solver.Solve(model);
|
||||
|
||||
if (status == CpSolverStatus.Optimal)
|
||||
{
|
||||
if (status == CpSolverStatus.Optimal) {
|
||||
Console.WriteLine("Optimal Schedule Length: " + solver.ObjectiveValue);
|
||||
Console.WriteLine("Task 0 starts at " + solver.Value(start_0));
|
||||
Console.WriteLine("Task 1 starts at " + solver.Value(start_1));
|
||||
@@ -1086,8 +1079,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class RankingSampleSat
|
||||
{
|
||||
public class RankingSampleSat {
|
||||
static void RankTasks(CpModel model,
|
||||
IntVar[] starts,
|
||||
ILiteral[] presences,
|
||||
@@ -1143,8 +1135,7 @@ public class RankingSampleSat
|
||||
}
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
static void Main() {
|
||||
CpModel model = new CpModel();
|
||||
// Three weeks.
|
||||
int horizon = 100;
|
||||
|
||||
@@ -176,10 +176,8 @@ Parameters must be passed as string to the solver.
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class SolveWithTimeLimitSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class SolveWithTimeLimitSampleSat {
|
||||
static void Main() {
|
||||
// Creates the model.
|
||||
CpModel model = new CpModel();
|
||||
// Creates the variables.
|
||||
@@ -199,8 +197,7 @@ public class SolveWithTimeLimitSampleSat
|
||||
|
||||
CpSolverStatus status = solver.Solve(model);
|
||||
|
||||
if (status == CpSolverStatus.Feasible)
|
||||
{
|
||||
if (status == CpSolverStatus.Optimal) {
|
||||
Console.WriteLine("x = " + solver.Value(x));
|
||||
Console.WriteLine("y = " + solver.Value(y));
|
||||
Console.WriteLine("z = " + solver.Value(z));
|
||||
@@ -397,10 +394,8 @@ public class SolveAndPrintIntermediateSolutionsSampleSat {
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class VarArraySolutionPrinterWithObjective : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinterWithObjective(IntVar[] variables)
|
||||
{
|
||||
public class VarArraySolutionPrinterWithObjective : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinterWithObjective(IntVar[] variables) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
||||
@@ -418,8 +413,7 @@ public class VarArraySolutionPrinterWithObjective : CpSolverSolutionCallback
|
||||
solution_count_++;
|
||||
}
|
||||
|
||||
public int SolutionCount()
|
||||
{
|
||||
public int SolutionCount() {
|
||||
return solution_count_;
|
||||
}
|
||||
|
||||
@@ -427,10 +421,8 @@ public class VarArraySolutionPrinterWithObjective : CpSolverSolutionCallback
|
||||
private IntVar[] variables_;
|
||||
}
|
||||
|
||||
public class SolveAndPrintIntermediateSolutionsSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class SolveAndPrintIntermediateSolutionsSampleSat {
|
||||
static void Main() {
|
||||
// Creates the model.
|
||||
CpModel model = new CpModel();
|
||||
|
||||
@@ -648,15 +640,12 @@ As in Python, CpSolver.SearchAllSolutions() must be called.
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinter(IntVar[] variables)
|
||||
{
|
||||
public class VarArraySolutionPrinter : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinter(IntVar[] variables) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
||||
public override void OnSolutionCallback()
|
||||
{
|
||||
public override void OnSolutionCallback() {
|
||||
{
|
||||
Console.WriteLine(String.Format("Solution #{0}: time = {1:F2} s",
|
||||
solution_count_, WallTime()));
|
||||
@@ -669,8 +658,7 @@ public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
}
|
||||
}
|
||||
|
||||
public int SolutionCount()
|
||||
{
|
||||
public int SolutionCount() {
|
||||
return solution_count_;
|
||||
}
|
||||
|
||||
@@ -678,10 +666,8 @@ public class VarArraySolutionPrinter : CpSolverSolutionCallback
|
||||
private IntVar[] variables_;
|
||||
}
|
||||
|
||||
public class SearchForAllSolutionsSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class SearchForAllSolutionsSampleSat {
|
||||
static void Main() {
|
||||
// Creates the model.
|
||||
CpModel model = new CpModel();
|
||||
|
||||
@@ -916,17 +902,13 @@ CpSolverSolutionCallback.OnSolutionCallback().
|
||||
using System;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
public class VarArraySolutionPrinterWithLimit : CpSolverSolutionCallback
|
||||
{
|
||||
public VarArraySolutionPrinterWithLimit(IntVar[] variables,
|
||||
int solution_limit)
|
||||
{
|
||||
public class VarArraySolutionPrinterWithLimit : CpSolverSolutionCallback {
|
||||
public VarArraySolutionPrinterWithLimit(IntVar[] variables, int solution_limit) {
|
||||
variables_ = variables;
|
||||
solution_limit_ = solution_limit;
|
||||
}
|
||||
|
||||
public override void OnSolutionCallback()
|
||||
{
|
||||
public override void OnSolutionCallback() {
|
||||
Console.WriteLine(String.Format("Solution #{0}: time = {1:F2} s",
|
||||
solution_count_, WallTime()));
|
||||
foreach (IntVar v in variables_)
|
||||
@@ -935,8 +917,7 @@ public class VarArraySolutionPrinterWithLimit : CpSolverSolutionCallback
|
||||
String.Format(" {0} = {1}", v.ShortString(), Value(v)));
|
||||
}
|
||||
solution_count_++;
|
||||
if (solution_count_ >= solution_limit_)
|
||||
{
|
||||
if (solution_count_ >= solution_limit_) {
|
||||
Console.WriteLine(
|
||||
String.Format("Stopping search after {0} solutions",
|
||||
solution_limit_));
|
||||
@@ -944,8 +925,7 @@ public class VarArraySolutionPrinterWithLimit : CpSolverSolutionCallback
|
||||
}
|
||||
}
|
||||
|
||||
public int SolutionCount()
|
||||
{
|
||||
public int SolutionCount() {
|
||||
return solution_count_;
|
||||
}
|
||||
|
||||
@@ -954,10 +934,8 @@ public class VarArraySolutionPrinterWithLimit : CpSolverSolutionCallback
|
||||
private int solution_limit_;
|
||||
}
|
||||
|
||||
public class StopAfterNSolutionsSampleSat
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
public class StopAfterNSolutionsSampleSat {
|
||||
static void Main() {
|
||||
// Creates the model.
|
||||
CpModel model = new CpModel();
|
||||
// Creates the variables.
|
||||
|
||||
Reference in New Issue
Block a user