Sync C# indent
This commit is contained in:
@@ -13,20 +13,20 @@
|
||||
|
||||
namespace Google.OrTools.ConstraintSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// int[] and long[] helper class.
|
||||
public static class IntArrayHelper
|
||||
// int[] and long[] helper class.
|
||||
public static class IntArrayHelper
|
||||
{
|
||||
public static IntExpr Element(this int[] array, IntExpr index)
|
||||
{
|
||||
public static IntExpr Element(this int[] array, IntExpr index)
|
||||
{
|
||||
return index.solver().MakeElement(array, index.Var());
|
||||
}
|
||||
public static IntExpr Element(this long[] array, IntExpr index)
|
||||
{
|
||||
return index.solver().MakeElement(array, index.Var());
|
||||
}
|
||||
return index.solver().MakeElement(array, index.Var());
|
||||
}
|
||||
public static IntExpr Element(this long[] array, IntExpr index)
|
||||
{
|
||||
return index.solver().MakeElement(array, index.Var());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Google.OrTools.ConstraintSolver
|
||||
|
||||
@@ -13,381 +13,381 @@
|
||||
|
||||
namespace Google.OrTools.ConstraintSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// IntVar[] helper class.
|
||||
public static class IntVarArrayHelper
|
||||
// IntVar[] helper class.
|
||||
public static class IntVarArrayHelper
|
||||
{
|
||||
// All Different
|
||||
public static Constraint AllDifferent(this IntVar[] vars)
|
||||
{
|
||||
// All Different
|
||||
public static Constraint AllDifferent(this IntVar[] vars)
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeAllDifferent(vars);
|
||||
}
|
||||
// Allowed assignment
|
||||
public static Constraint AllowedAssignments(this IntVar[] vars, IntTupleSet tuples)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeAllowedAssignments(vars, tuples);
|
||||
}
|
||||
// sum of all vars.
|
||||
public static IntExpr Sum(this IntVar[] vars)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeSum(vars);
|
||||
}
|
||||
// sum of all constraints.
|
||||
public static IntExpr Sum(this IConstraintWithStatus[] cts)
|
||||
{
|
||||
Solver solver = GetSolver(cts);
|
||||
IntVar[] vars = new IntVar[cts.Length];
|
||||
for (int i = 0; i < cts.Length; ++i)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeAllDifferent(vars);
|
||||
vars[i] = cts[i].Var();
|
||||
}
|
||||
// Allowed assignment
|
||||
public static Constraint AllowedAssignments(this IntVar[] vars, IntTupleSet tuples)
|
||||
return solver.MakeSum(vars);
|
||||
}
|
||||
public static IntExpr Sum(this IntExpr[] exprs)
|
||||
{
|
||||
Solver solver = GetSolver(exprs);
|
||||
IntVar[] vars = new IntVar[exprs.Length];
|
||||
for (int i = 0; i < exprs.Length; ++i)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeAllowedAssignments(vars, tuples);
|
||||
}
|
||||
// sum of all vars.
|
||||
public static IntExpr Sum(this IntVar[] vars)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeSum(vars);
|
||||
}
|
||||
// sum of all constraints.
|
||||
public static IntExpr Sum(this IConstraintWithStatus[] cts)
|
||||
{
|
||||
Solver solver = GetSolver(cts);
|
||||
IntVar[] vars = new IntVar[cts.Length];
|
||||
for (int i = 0; i < cts.Length; ++i)
|
||||
{
|
||||
vars[i] = cts[i].Var();
|
||||
}
|
||||
return solver.MakeSum(vars);
|
||||
}
|
||||
public static IntExpr Sum(this IntExpr[] exprs)
|
||||
{
|
||||
Solver solver = GetSolver(exprs);
|
||||
IntVar[] vars = new IntVar[exprs.Length];
|
||||
for (int i = 0; i < exprs.Length; ++i)
|
||||
{
|
||||
vars[i] = exprs[i].Var();
|
||||
}
|
||||
return solver.MakeSum(vars);
|
||||
}
|
||||
|
||||
// scalar product
|
||||
public static IntExpr ScalProd(this IntVar[] vars, long[] coefs)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeScalProd(vars, coefs);
|
||||
}
|
||||
|
||||
// scalar product
|
||||
public static IntExpr ScalProd(this IntVar[] vars, int[] coefs)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeScalProd(vars, coefs);
|
||||
}
|
||||
|
||||
// get solver from array of integer variables
|
||||
private static Solver GetSolver(IntVar[] vars)
|
||||
{
|
||||
if (vars == null || vars.Length <= 0)
|
||||
throw new ArgumentException("Array <vars> cannot be null or empty");
|
||||
|
||||
return vars[0].solver();
|
||||
}
|
||||
// get solver from array of integer expressions
|
||||
private static Solver GetSolver(IntExpr[] expressions)
|
||||
{
|
||||
if (expressions == null || expressions.Length <= 0)
|
||||
throw new ArgumentException("Array <expr> cannot be null or empty");
|
||||
|
||||
return expressions[0].solver();
|
||||
}
|
||||
private static Solver GetSolver(IConstraintWithStatus[] cts)
|
||||
{
|
||||
if (cts == null || cts.Length <= 0)
|
||||
throw new ArgumentException("Array <cts> cannot be null or empty");
|
||||
|
||||
return cts[0].solver();
|
||||
}
|
||||
public static IntExpr Element(this IntVar[] array, IntExpr index)
|
||||
{
|
||||
return index.solver().MakeElement(array, index.Var());
|
||||
}
|
||||
// min of all vars.
|
||||
public static IntExpr Min(this IntVar[] vars)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeMin(vars);
|
||||
}
|
||||
// min of all vars.
|
||||
public static IntExpr Max(this IntVar[] vars)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeMax(vars);
|
||||
}
|
||||
// count of all vars.
|
||||
public static Constraint Count(this IntVar[] vars, long value, long count)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCount(vars, value, count);
|
||||
}
|
||||
// count of all vars.
|
||||
public static Constraint Count(this IntVar[] vars, long value, IntExpr count)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCount(vars, value, count.Var());
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, long[] values, IntVar[] cards)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, values, cards);
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, int[] values, IntVar[] cards)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, values, cards);
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, IntVar[] cards)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, cards);
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, long card_min, long card_max, long card_size)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, card_min, card_max, card_size);
|
||||
}
|
||||
public static Constraint Transition(this IntVar[] vars, IntTupleSet transitions, long initial_state,
|
||||
long[] final_states)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeTransitionConstraint(vars, transitions, initial_state, final_states);
|
||||
}
|
||||
public static Constraint Transition(this IntVar[] vars, IntTupleSet transitions, long initial_state,
|
||||
int[] final_states)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeTransitionConstraint(vars, transitions, initial_state, final_states);
|
||||
}
|
||||
|
||||
// Matrix API
|
||||
public static IntVar[] Flatten(this IntVar[,] vars)
|
||||
{
|
||||
int rows = vars.GetLength(0);
|
||||
int cols = vars.GetLength(1);
|
||||
IntVar[] flat = new IntVar[cols * rows];
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
for (int j = 0; j < cols; j++)
|
||||
{
|
||||
flat[i * cols + j] = vars[i, j];
|
||||
}
|
||||
}
|
||||
return flat;
|
||||
vars[i] = exprs[i].Var();
|
||||
}
|
||||
return solver.MakeSum(vars);
|
||||
}
|
||||
|
||||
// TODO(user): Try to move this code back to the .swig with @define macros.
|
||||
public partial class IntVarVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
// scalar product
|
||||
public static IntExpr ScalProd(this IntVar[] vars, long[] coefs)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeScalProd(vars, coefs);
|
||||
}
|
||||
|
||||
// scalar product
|
||||
public static IntExpr ScalProd(this IntVar[] vars, int[] coefs)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeScalProd(vars, coefs);
|
||||
}
|
||||
|
||||
// get solver from array of integer variables
|
||||
private static Solver GetSolver(IntVar[] vars)
|
||||
{
|
||||
if (vars == null || vars.Length <= 0)
|
||||
throw new ArgumentException("Array <vars> cannot be null or empty");
|
||||
|
||||
return vars[0].solver();
|
||||
}
|
||||
// get solver from array of integer expressions
|
||||
private static Solver GetSolver(IntExpr[] expressions)
|
||||
{
|
||||
if (expressions == null || expressions.Length <= 0)
|
||||
throw new ArgumentException("Array <expr> cannot be null or empty");
|
||||
|
||||
return expressions[0].solver();
|
||||
}
|
||||
private static Solver GetSolver(IConstraintWithStatus[] cts)
|
||||
{
|
||||
if (cts == null || cts.Length <= 0)
|
||||
throw new ArgumentException("Array <cts> cannot be null or empty");
|
||||
|
||||
return cts[0].solver();
|
||||
}
|
||||
public static IntExpr Element(this IntVar[] array, IntExpr index)
|
||||
{
|
||||
return index.solver().MakeElement(array, index.Var());
|
||||
}
|
||||
// min of all vars.
|
||||
public static IntExpr Min(this IntVar[] vars)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeMin(vars);
|
||||
}
|
||||
// min of all vars.
|
||||
public static IntExpr Max(this IntVar[] vars)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeMax(vars);
|
||||
}
|
||||
// count of all vars.
|
||||
public static Constraint Count(this IntVar[] vars, long value, long count)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCount(vars, value, count);
|
||||
}
|
||||
// count of all vars.
|
||||
public static Constraint Count(this IntVar[] vars, long value, IntExpr count)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCount(vars, value, count.Var());
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, long[] values, IntVar[] cards)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, values, cards);
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, int[] values, IntVar[] cards)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, values, cards);
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, IntVar[] cards)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, cards);
|
||||
}
|
||||
public static Constraint Distribute(this IntVar[] vars, long card_min, long card_max, long card_size)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDistribute(vars, card_min, card_max, card_size);
|
||||
}
|
||||
public static Constraint Transition(this IntVar[] vars, IntTupleSet transitions, long initial_state,
|
||||
long[] final_states)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeTransitionConstraint(vars, transitions, initial_state, final_states);
|
||||
}
|
||||
public static Constraint Transition(this IntVar[] vars, IntTupleSet transitions, long initial_state,
|
||||
int[] final_states)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeTransitionConstraint(vars, transitions, initial_state, final_states);
|
||||
}
|
||||
|
||||
// Matrix API
|
||||
public static IntVar[] Flatten(this IntVar[,] vars)
|
||||
{
|
||||
int rows = vars.GetLength(0);
|
||||
int cols = vars.GetLength(1);
|
||||
IntVar[] flat = new IntVar[cols * rows];
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
for (int j = 0; j < cols; j++)
|
||||
{
|
||||
flat[i * cols + j] = vars[i, j];
|
||||
}
|
||||
}
|
||||
return flat;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(user): Try to move this code back to the .swig with @define macros.
|
||||
public partial class IntVarVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<IntVar>
|
||||
,
|
||||
System.Collections.Generic.IList<IntVar>
|
||||
#endif
|
||||
{
|
||||
// cast from C# IntVar array
|
||||
public static implicit operator IntVarVector(IntVar[] inVal)
|
||||
{
|
||||
// cast from C# IntVar array
|
||||
public static implicit operator IntVarVector(IntVar[] inVal)
|
||||
var outVal = new IntVarVector();
|
||||
foreach (IntVar element in inVal)
|
||||
{
|
||||
var outVal = new IntVarVector();
|
||||
foreach (IntVar element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# IntVar array
|
||||
public static implicit operator IntVar[](IntVarVector inVal)
|
||||
{
|
||||
var outVal = new IntVar[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
public partial class SearchMonitorVector : IDisposable,
|
||||
// cast to C# IntVar array
|
||||
public static implicit operator IntVar[](IntVarVector inVal)
|
||||
{
|
||||
var outVal = new IntVar[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SearchMonitorVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<SearchMonitor>
|
||||
#endif
|
||||
{
|
||||
// cast from C# SearchMonitor array
|
||||
public static implicit operator SearchMonitorVector(SearchMonitor[] inVal)
|
||||
{
|
||||
var outVal = new SearchMonitorVector();
|
||||
foreach (SearchMonitor element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# SearchMonitor array
|
||||
public static implicit operator SearchMonitor[](SearchMonitorVector inVal)
|
||||
{
|
||||
var outVal = new SearchMonitor[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DecisionBuilderVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<DecisionBuilder>
|
||||
#endif
|
||||
{
|
||||
// cast from C# DecisionBuilder array
|
||||
public static implicit operator DecisionBuilderVector(DecisionBuilder[] inVal)
|
||||
{
|
||||
var outVal = new DecisionBuilderVector();
|
||||
foreach (DecisionBuilder element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# DecisionBuilder array
|
||||
public static implicit operator DecisionBuilder[](DecisionBuilderVector inVal)
|
||||
{
|
||||
var outVal = new DecisionBuilder[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class IntervalVarVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<IntervalVar>
|
||||
#endif
|
||||
{
|
||||
// cast from C# IntervalVar array
|
||||
public static implicit operator IntervalVarVector(IntervalVar[] inVal)
|
||||
{
|
||||
var outVal = new IntervalVarVector();
|
||||
foreach (IntervalVar element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# IntervalVar array
|
||||
public static implicit operator IntervalVar[](IntervalVarVector inVal)
|
||||
{
|
||||
var outVal = new IntervalVar[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SequenceVarVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<SequenceVar>
|
||||
#endif
|
||||
{
|
||||
// cast from C# SequenceVar array
|
||||
public static implicit operator SequenceVarVector(SequenceVar[] inVal)
|
||||
{
|
||||
var outVal = new SequenceVarVector();
|
||||
foreach (SequenceVar element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# SequenceVar array
|
||||
public static implicit operator SequenceVar[](SequenceVarVector inVal)
|
||||
{
|
||||
var outVal = new SequenceVar[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class LocalSearchOperatorVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<LocalSearchOperator>
|
||||
#endif
|
||||
{
|
||||
// cast from C# LocalSearchOperator array
|
||||
public static implicit operator LocalSearchOperatorVector(LocalSearchOperator[] inVal)
|
||||
{
|
||||
var outVal = new LocalSearchOperatorVector();
|
||||
foreach (LocalSearchOperator element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# LocalSearchOperator array
|
||||
public static implicit operator LocalSearchOperator[](LocalSearchOperatorVector inVal)
|
||||
{
|
||||
var outVal = new LocalSearchOperator[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class LocalSearchFilterVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<SearchMonitor>
|
||||
,
|
||||
System.Collections.Generic.IList<LocalSearchFilter>
|
||||
#endif
|
||||
{
|
||||
// cast from C# LocalSearchFilter array
|
||||
public static implicit operator LocalSearchFilterVector(LocalSearchFilter[] inVal)
|
||||
{
|
||||
// cast from C# SearchMonitor array
|
||||
public static implicit operator SearchMonitorVector(SearchMonitor[] inVal)
|
||||
var outVal = new LocalSearchFilterVector();
|
||||
foreach (LocalSearchFilter element in inVal)
|
||||
{
|
||||
var outVal = new SearchMonitorVector();
|
||||
foreach (SearchMonitor element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# SearchMonitor array
|
||||
public static implicit operator SearchMonitor[](SearchMonitorVector inVal)
|
||||
{
|
||||
var outVal = new SearchMonitor[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
public partial class DecisionBuilderVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<DecisionBuilder>
|
||||
#endif
|
||||
// cast to C# LocalSearchFilter array
|
||||
public static implicit operator LocalSearchFilter[](LocalSearchFilterVector inVal)
|
||||
{
|
||||
// cast from C# DecisionBuilder array
|
||||
public static implicit operator DecisionBuilderVector(DecisionBuilder[] inVal)
|
||||
{
|
||||
var outVal = new DecisionBuilderVector();
|
||||
foreach (DecisionBuilder element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# DecisionBuilder array
|
||||
public static implicit operator DecisionBuilder[](DecisionBuilderVector inVal)
|
||||
{
|
||||
var outVal = new DecisionBuilder[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
var outVal = new LocalSearchFilter[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class IntervalVarVector : IDisposable,
|
||||
public partial class SymmetryBreakerVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<IntervalVar>
|
||||
,
|
||||
System.Collections.Generic.IList<SymmetryBreaker>
|
||||
#endif
|
||||
{
|
||||
// cast from C# SymmetryBreaker array
|
||||
public static implicit operator SymmetryBreakerVector(SymmetryBreaker[] inVal)
|
||||
{
|
||||
// cast from C# IntervalVar array
|
||||
public static implicit operator IntervalVarVector(IntervalVar[] inVal)
|
||||
var outVal = new SymmetryBreakerVector();
|
||||
foreach (SymmetryBreaker element in inVal)
|
||||
{
|
||||
var outVal = new IntervalVarVector();
|
||||
foreach (IntervalVar element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# IntervalVar array
|
||||
public static implicit operator IntervalVar[](IntervalVarVector inVal)
|
||||
{
|
||||
var outVal = new IntervalVar[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
public partial class SequenceVarVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<SequenceVar>
|
||||
#endif
|
||||
// cast to C# SymmetryBreaker array
|
||||
public static implicit operator SymmetryBreaker[](SymmetryBreakerVector inVal)
|
||||
{
|
||||
// cast from C# SequenceVar array
|
||||
public static implicit operator SequenceVarVector(SequenceVar[] inVal)
|
||||
{
|
||||
var outVal = new SequenceVarVector();
|
||||
foreach (SequenceVar element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# SequenceVar array
|
||||
public static implicit operator SequenceVar[](SequenceVarVector inVal)
|
||||
{
|
||||
var outVal = new SequenceVar[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class LocalSearchOperatorVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<LocalSearchOperator>
|
||||
#endif
|
||||
{
|
||||
// cast from C# LocalSearchOperator array
|
||||
public static implicit operator LocalSearchOperatorVector(LocalSearchOperator[] inVal)
|
||||
{
|
||||
var outVal = new LocalSearchOperatorVector();
|
||||
foreach (LocalSearchOperator element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# LocalSearchOperator array
|
||||
public static implicit operator LocalSearchOperator[](LocalSearchOperatorVector inVal)
|
||||
{
|
||||
var outVal = new LocalSearchOperator[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class LocalSearchFilterVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<LocalSearchFilter>
|
||||
#endif
|
||||
{
|
||||
// cast from C# LocalSearchFilter array
|
||||
public static implicit operator LocalSearchFilterVector(LocalSearchFilter[] inVal)
|
||||
{
|
||||
var outVal = new LocalSearchFilterVector();
|
||||
foreach (LocalSearchFilter element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# LocalSearchFilter array
|
||||
public static implicit operator LocalSearchFilter[](LocalSearchFilterVector inVal)
|
||||
{
|
||||
var outVal = new LocalSearchFilter[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SymmetryBreakerVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<SymmetryBreaker>
|
||||
#endif
|
||||
{
|
||||
// cast from C# SymmetryBreaker array
|
||||
public static implicit operator SymmetryBreakerVector(SymmetryBreaker[] inVal)
|
||||
{
|
||||
var outVal = new SymmetryBreakerVector();
|
||||
foreach (SymmetryBreaker element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# SymmetryBreaker array
|
||||
public static implicit operator SymmetryBreaker[](SymmetryBreakerVector inVal)
|
||||
{
|
||||
var outVal = new SymmetryBreaker[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
var outVal = new SymmetryBreaker[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools.ConstraintSolver
|
||||
|
||||
@@ -13,34 +13,34 @@
|
||||
|
||||
namespace Google.OrTools.ConstraintSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// IntervalVar[] helper class.
|
||||
public static class IntervalVarArrayHelper
|
||||
// IntervalVar[] helper class.
|
||||
public static class IntervalVarArrayHelper
|
||||
{
|
||||
// get solver from array of interval variables
|
||||
private static Solver GetSolver(IntervalVar[] vars)
|
||||
{
|
||||
// get solver from array of interval variables
|
||||
private static Solver GetSolver(IntervalVar[] vars)
|
||||
{
|
||||
if (vars == null || vars.Length <= 0)
|
||||
throw new ArgumentException("Array <vars> cannot be null or empty");
|
||||
if (vars == null || vars.Length <= 0)
|
||||
throw new ArgumentException("Array <vars> cannot be null or empty");
|
||||
|
||||
return vars[0].solver();
|
||||
}
|
||||
public static DisjunctiveConstraint Disjunctive(this IntervalVar[] vars, String name)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDisjunctiveConstraint(vars, name);
|
||||
}
|
||||
public static Constraint Cumulative(this IntervalVar[] vars, long[] demands, long capacity, String name)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCumulative(vars, demands, capacity, name);
|
||||
}
|
||||
public static Constraint Cumulative(this IntervalVar[] vars, int[] demands, long capacity, String name)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCumulative(vars, demands, capacity, name);
|
||||
}
|
||||
return vars[0].solver();
|
||||
}
|
||||
public static DisjunctiveConstraint Disjunctive(this IntervalVar[] vars, String name)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeDisjunctiveConstraint(vars, name);
|
||||
}
|
||||
public static Constraint Cumulative(this IntervalVar[] vars, long[] demands, long capacity, String name)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCumulative(vars, demands, capacity, name);
|
||||
}
|
||||
public static Constraint Cumulative(this IntervalVar[] vars, int[] demands, long capacity, String name)
|
||||
{
|
||||
Solver solver = GetSolver(vars);
|
||||
return solver.MakeCumulative(vars, demands, capacity, name);
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools.ConstraintSolver
|
||||
|
||||
@@ -15,220 +15,220 @@ using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Google.OrTools.ConstraintSolver
|
||||
{
|
||||
/**
|
||||
* This class acts as a intermediate step between a c++ decision builder and a
|
||||
* .Net one. Its main purpose is to catch the .Net application exception
|
||||
* launched when a failure occurs during the Next() call, and to return
|
||||
* silently a System.ApplicationException that will propagate the failure back
|
||||
* to the C++ code.
|
||||
*
|
||||
*/
|
||||
public class NetDecisionBuilder : DecisionBuilder
|
||||
{
|
||||
/**
|
||||
* This class acts as a intermediate step between a c++ decision builder and a
|
||||
* .Net one. Its main purpose is to catch the .Net application exception
|
||||
* launched when a failure occurs during the Next() call, and to return
|
||||
* silently a System.ApplicationException that will propagate the failure back
|
||||
* to the C++ code.
|
||||
*
|
||||
* This methods wraps the calls to next() and catches fail exceptions.
|
||||
* It currently catches all application exceptions.
|
||||
*/
|
||||
public class NetDecisionBuilder : DecisionBuilder
|
||||
public override Decision NextWrapper(Solver solver)
|
||||
{
|
||||
/**
|
||||
* This methods wraps the calls to next() and catches fail exceptions.
|
||||
* It currently catches all application exceptions.
|
||||
*/
|
||||
public override Decision NextWrapper(Solver solver)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
return Next(solver);
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Catch only fail exceptions.
|
||||
return solver.MakeFailDecision();
|
||||
}
|
||||
return Next(solver);
|
||||
}
|
||||
/**
|
||||
* This is the new method to subclass when defining a .Net decision builder.
|
||||
*/
|
||||
public virtual Decision Next(Solver solver)
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
return null;
|
||||
// TODO(user): Catch only fail exceptions.
|
||||
return solver.MakeFailDecision();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class acts as a intermediate step between a c++ decision and a
|
||||
* .Net one. Its main purpose is to catch the .Net application
|
||||
* exception launched when a failure occurs during the
|
||||
* Apply()/Refute() calls, and to set the ShouldFail() flag on the
|
||||
* solver that will propagate the failure back to the C++ code.
|
||||
*
|
||||
* This is the new method to subclass when defining a .Net decision builder.
|
||||
*/
|
||||
public class NetDecision : Decision
|
||||
public virtual Decision Next(Solver solver)
|
||||
{
|
||||
/**
|
||||
* This methods wraps the calls to Apply() and catches fail exceptions.
|
||||
* It currently catches all application exceptions.
|
||||
*/
|
||||
public override void ApplyWrapper(Solver solver)
|
||||
{
|
||||
try
|
||||
{
|
||||
Apply(solver);
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Catch only fail exceptions.
|
||||
solver.ShouldFail();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This is a new method to subclass when defining a .Net decision.
|
||||
*/
|
||||
public virtual void Apply(Solver solver)
|
||||
{
|
||||
// By default, do nothing
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void RefuteWrapper(Solver solver)
|
||||
/**
|
||||
* This class acts as a intermediate step between a c++ decision and a
|
||||
* .Net one. Its main purpose is to catch the .Net application
|
||||
* exception launched when a failure occurs during the
|
||||
* Apply()/Refute() calls, and to set the ShouldFail() flag on the
|
||||
* solver that will propagate the failure back to the C++ code.
|
||||
*
|
||||
*/
|
||||
public class NetDecision : Decision
|
||||
{
|
||||
/**
|
||||
* This methods wraps the calls to Apply() and catches fail exceptions.
|
||||
* It currently catches all application exceptions.
|
||||
*/
|
||||
public override void ApplyWrapper(Solver solver)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Refute(solver);
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Catch only fail exceptions.
|
||||
solver.ShouldFail();
|
||||
}
|
||||
Apply(solver);
|
||||
}
|
||||
/**
|
||||
* This is a new method to subclass when defining a .Net decision.
|
||||
*/
|
||||
public virtual void Refute(Solver solver)
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Catch only fail exceptions.
|
||||
solver.ShouldFail();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This is a new method to subclass when defining a .Net decision.
|
||||
*/
|
||||
public virtual void Apply(Solver solver)
|
||||
{
|
||||
// By default, do nothing
|
||||
}
|
||||
|
||||
public override void RefuteWrapper(Solver solver)
|
||||
{
|
||||
try
|
||||
{
|
||||
Refute(solver);
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Catch only fail exceptions.
|
||||
solver.ShouldFail();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This is a new method to subclass when defining a .Net decision.
|
||||
*/
|
||||
public virtual void Refute(Solver solver)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class NetDemon : Demon
|
||||
{
|
||||
/**
|
||||
* This methods wraps the calls to next() and catches fail exceptions.
|
||||
*/
|
||||
public override void RunWrapper(Solver solver)
|
||||
{
|
||||
try
|
||||
{
|
||||
Run(solver);
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Check that this is indeed a fail. Try implementing
|
||||
// custom exceptions (hard).
|
||||
solver.ShouldFail();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This is the new method to subclass when defining a .Net decision builder.
|
||||
*/
|
||||
public virtual void Run(Solver solver)
|
||||
{
|
||||
}
|
||||
public override int Priority()
|
||||
{
|
||||
return Solver.NORMAL_PRIORITY;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "NetDemon";
|
||||
}
|
||||
}
|
||||
|
||||
public class NetConstraint : Constraint
|
||||
{
|
||||
public NetConstraint(Solver s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitialPropagateWrapper()
|
||||
{
|
||||
try
|
||||
{
|
||||
InitialPropagate();
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
solver().ShouldFail();
|
||||
}
|
||||
}
|
||||
public virtual void InitialPropagate()
|
||||
{
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "NetConstraint";
|
||||
}
|
||||
}
|
||||
|
||||
public class IntVarEnumerator : IEnumerator
|
||||
{
|
||||
private IntVarIterator iterator_;
|
||||
|
||||
// Enumerators are positioned before the first element
|
||||
// until the first MoveNext() call.
|
||||
private bool first_ = true;
|
||||
|
||||
public IntVarEnumerator(IntVarIterator iterator)
|
||||
{
|
||||
iterator_ = iterator;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (first_)
|
||||
{
|
||||
iterator_.Init();
|
||||
first_ = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator_.Next();
|
||||
}
|
||||
return iterator_.Ok();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
first_ = true;
|
||||
}
|
||||
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get {
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
|
||||
public class NetDemon : Demon
|
||||
public long Current
|
||||
{
|
||||
/**
|
||||
* This methods wraps the calls to next() and catches fail exceptions.
|
||||
*/
|
||||
public override void RunWrapper(Solver solver)
|
||||
{
|
||||
try
|
||||
get {
|
||||
if (!first_ && iterator_.Ok())
|
||||
{
|
||||
Run(solver);
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
// TODO(user): Check that this is indeed a fail. Try implementing
|
||||
// custom exceptions (hard).
|
||||
solver.ShouldFail();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This is the new method to subclass when defining a .Net decision builder.
|
||||
*/
|
||||
public virtual void Run(Solver solver)
|
||||
{
|
||||
}
|
||||
public override int Priority()
|
||||
{
|
||||
return Solver.NORMAL_PRIORITY;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "NetDemon";
|
||||
}
|
||||
}
|
||||
|
||||
public class NetConstraint : Constraint
|
||||
{
|
||||
public NetConstraint(Solver s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitialPropagateWrapper()
|
||||
{
|
||||
try
|
||||
{
|
||||
InitialPropagate();
|
||||
}
|
||||
catch (ApplicationException /*e*/)
|
||||
{
|
||||
solver().ShouldFail();
|
||||
}
|
||||
}
|
||||
public virtual void InitialPropagate()
|
||||
{
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "NetConstraint";
|
||||
}
|
||||
}
|
||||
|
||||
public class IntVarEnumerator : IEnumerator
|
||||
{
|
||||
private IntVarIterator iterator_;
|
||||
|
||||
// Enumerators are positioned before the first element
|
||||
// until the first MoveNext() call.
|
||||
private bool first_ = true;
|
||||
|
||||
public IntVarEnumerator(IntVarIterator iterator)
|
||||
{
|
||||
iterator_ = iterator;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (first_)
|
||||
{
|
||||
iterator_.Init();
|
||||
first_ = false;
|
||||
return iterator_.Value();
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator_.Next();
|
||||
}
|
||||
return iterator_.Ok();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
first_ = true;
|
||||
}
|
||||
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get {
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
|
||||
public long Current
|
||||
{
|
||||
get {
|
||||
if (!first_ && iterator_.Ok())
|
||||
{
|
||||
return iterator_.Value();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class IntVarIterator : BaseObject, IEnumerable
|
||||
public partial class IntVarIterator : BaseObject, IEnumerable
|
||||
{
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return (IEnumerator)GetEnumerator();
|
||||
}
|
||||
|
||||
public IntVarEnumerator GetEnumerator()
|
||||
{
|
||||
return new IntVarEnumerator(this);
|
||||
}
|
||||
return (IEnumerator)GetEnumerator();
|
||||
}
|
||||
|
||||
public IntVarEnumerator GetEnumerator()
|
||||
{
|
||||
return new IntVarEnumerator(this);
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools.ConstraintSolver
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,316 +13,316 @@
|
||||
|
||||
namespace Google.OrTools.ConstraintSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface IConstraintWithStatus
|
||||
public interface IConstraintWithStatus
|
||||
{
|
||||
Solver solver();
|
||||
IntVar Var();
|
||||
}
|
||||
|
||||
public abstract class BaseEquality : IConstraintWithStatus
|
||||
{
|
||||
abstract public Solver solver();
|
||||
abstract public IntVar Var();
|
||||
|
||||
public static IntExpr operator +(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), b.Var());
|
||||
}
|
||||
public static IntExpr operator +(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator +(long v, BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator -(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return a.solver().MakeDifference(a.Var(), b.Var());
|
||||
}
|
||||
public static IntExpr operator -(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), -v);
|
||||
}
|
||||
public static IntExpr operator -(long v, BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeDifference(v, a.Var());
|
||||
}
|
||||
public static IntExpr operator *(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return a.solver().MakeProd(a.Var(), b.Var());
|
||||
}
|
||||
public static IntExpr operator *(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeProd(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator *(long v, BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeProd(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator /(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeDiv(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator -(BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeOpposite(a.Var());
|
||||
}
|
||||
public IntExpr Abs()
|
||||
{
|
||||
return this.solver().MakeAbs(this.Var());
|
||||
}
|
||||
public IntExpr Square()
|
||||
{
|
||||
return this.solver().MakeSquare(this.Var());
|
||||
}
|
||||
public static WrappedConstraint operator ==(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator ==(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator !=(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeNonEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator !=(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeNonEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator >=(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreaterOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator >=(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLessOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator>(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreater(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator>(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLess(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator <=(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLessOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator <=(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreaterOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator<(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLess(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator<(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreater(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator >=(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreaterOrEqual(a.Var(), b.Var()));
|
||||
}
|
||||
public static WrappedConstraint operator>(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreater(a.Var(), b.Var()));
|
||||
}
|
||||
public static WrappedConstraint operator <=(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLessOrEqual(a.Var(), b.Var()));
|
||||
}
|
||||
public static WrappedConstraint operator<(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLess(a.Var(), b.Var()));
|
||||
}
|
||||
public static ConstraintEquality operator ==(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new ConstraintEquality(a, b, true);
|
||||
}
|
||||
public static ConstraintEquality operator !=(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new ConstraintEquality(a, b, false);
|
||||
}
|
||||
}
|
||||
|
||||
public class WrappedConstraint : BaseEquality
|
||||
{
|
||||
public bool Val { get; set; }
|
||||
|
||||
public Constraint Cst { get; set; }
|
||||
|
||||
public WrappedConstraint(Constraint cst) : this(true, cst)
|
||||
{
|
||||
Solver solver();
|
||||
IntVar Var();
|
||||
}
|
||||
|
||||
public abstract class BaseEquality : IConstraintWithStatus
|
||||
public WrappedConstraint(bool val) : this(val, null)
|
||||
{
|
||||
abstract public Solver solver();
|
||||
abstract public IntVar Var();
|
||||
|
||||
public static IntExpr operator +(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), b.Var());
|
||||
}
|
||||
public static IntExpr operator +(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator +(long v, BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator -(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return a.solver().MakeDifference(a.Var(), b.Var());
|
||||
}
|
||||
public static IntExpr operator -(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeSum(a.Var(), -v);
|
||||
}
|
||||
public static IntExpr operator -(long v, BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeDifference(v, a.Var());
|
||||
}
|
||||
public static IntExpr operator *(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return a.solver().MakeProd(a.Var(), b.Var());
|
||||
}
|
||||
public static IntExpr operator *(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeProd(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator *(long v, BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeProd(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator /(BaseEquality a, long v)
|
||||
{
|
||||
return a.solver().MakeDiv(a.Var(), v);
|
||||
}
|
||||
public static IntExpr operator -(BaseEquality a)
|
||||
{
|
||||
return a.solver().MakeOpposite(a.Var());
|
||||
}
|
||||
public IntExpr Abs()
|
||||
{
|
||||
return this.solver().MakeAbs(this.Var());
|
||||
}
|
||||
public IntExpr Square()
|
||||
{
|
||||
return this.solver().MakeSquare(this.Var());
|
||||
}
|
||||
public static WrappedConstraint operator ==(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator ==(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator !=(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeNonEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator !=(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeNonEquality(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator >=(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreaterOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator >=(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLessOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator>(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreater(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator>(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLess(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator <=(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLessOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator <=(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreaterOrEqual(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator<(BaseEquality a, long v)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLess(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator<(long v, BaseEquality a)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreater(a.Var(), v));
|
||||
}
|
||||
public static WrappedConstraint operator >=(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreaterOrEqual(a.Var(), b.Var()));
|
||||
}
|
||||
public static WrappedConstraint operator>(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeGreater(a.Var(), b.Var()));
|
||||
}
|
||||
public static WrappedConstraint operator <=(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLessOrEqual(a.Var(), b.Var()));
|
||||
}
|
||||
public static WrappedConstraint operator<(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new WrappedConstraint(a.solver().MakeLess(a.Var(), b.Var()));
|
||||
}
|
||||
public static ConstraintEquality operator ==(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new ConstraintEquality(a, b, true);
|
||||
}
|
||||
public static ConstraintEquality operator !=(BaseEquality a, BaseEquality b)
|
||||
{
|
||||
return new ConstraintEquality(a, b, false);
|
||||
}
|
||||
}
|
||||
|
||||
public class WrappedConstraint : BaseEquality
|
||||
public WrappedConstraint(bool val, Constraint cst)
|
||||
{
|
||||
public bool Val { get; set; }
|
||||
|
||||
public Constraint Cst { get; set; }
|
||||
|
||||
public WrappedConstraint(Constraint cst) : this(true, cst)
|
||||
{
|
||||
}
|
||||
|
||||
public WrappedConstraint(bool val) : this(val, null)
|
||||
{
|
||||
}
|
||||
|
||||
public WrappedConstraint(bool val, Constraint cst)
|
||||
{
|
||||
this.Val = val;
|
||||
this.Cst = cst;
|
||||
}
|
||||
|
||||
public static implicit operator bool(WrappedConstraint valCstPair)
|
||||
{
|
||||
return valCstPair.Val;
|
||||
}
|
||||
|
||||
public static implicit operator Constraint(WrappedConstraint valCstPair)
|
||||
{
|
||||
return valCstPair.Cst;
|
||||
}
|
||||
|
||||
public static implicit operator IntVar(WrappedConstraint eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public static implicit operator IntExpr(WrappedConstraint eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public override Solver solver()
|
||||
{
|
||||
return this.Cst.solver();
|
||||
}
|
||||
|
||||
public override IntVar Var()
|
||||
{
|
||||
return Cst.Var();
|
||||
}
|
||||
this.Val = val;
|
||||
this.Cst = cst;
|
||||
}
|
||||
|
||||
public class IntExprEquality : BaseEquality
|
||||
public static implicit operator bool(WrappedConstraint valCstPair)
|
||||
{
|
||||
public IntExprEquality(IntExpr a, IntExpr b, bool equality)
|
||||
{
|
||||
this.left_ = a;
|
||||
this.right_ = b;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
bool IsTrue()
|
||||
{
|
||||
return (object)left_ == (object)right_ ? equality_ : !equality_;
|
||||
}
|
||||
|
||||
Constraint ToConstraint()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeEquality(left_.Var(), right_.Var())
|
||||
: left_.solver().MakeNonEquality(left_.Var(), right_.Var());
|
||||
}
|
||||
|
||||
public static bool operator true(IntExprEquality eq)
|
||||
{
|
||||
return eq.IsTrue();
|
||||
}
|
||||
|
||||
public static bool operator false(IntExprEquality eq)
|
||||
{
|
||||
return !eq.IsTrue();
|
||||
}
|
||||
|
||||
public static implicit operator Constraint(IntExprEquality eq)
|
||||
{
|
||||
return eq.ToConstraint();
|
||||
}
|
||||
|
||||
public override IntVar Var()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeIsEqualVar(left_, right_)
|
||||
: left_.solver().MakeIsDifferentVar(left_, right_);
|
||||
}
|
||||
|
||||
public static implicit operator IntVar(IntExprEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public static implicit operator IntExpr(IntExprEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public override Solver solver()
|
||||
{
|
||||
return left_.solver();
|
||||
}
|
||||
|
||||
private IntExpr left_;
|
||||
private IntExpr right_;
|
||||
private bool equality_;
|
||||
return valCstPair.Val;
|
||||
}
|
||||
|
||||
public class ConstraintEquality : BaseEquality
|
||||
public static implicit operator Constraint(WrappedConstraint valCstPair)
|
||||
{
|
||||
public ConstraintEquality(IConstraintWithStatus a, IConstraintWithStatus b, bool equality)
|
||||
{
|
||||
this.left_ = a;
|
||||
this.right_ = b;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
bool IsTrue()
|
||||
{
|
||||
return (object)left_ == (object)right_ ? equality_ : !equality_;
|
||||
}
|
||||
|
||||
Constraint ToConstraint()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeEquality(left_.Var(), right_.Var())
|
||||
: left_.solver().MakeNonEquality(left_.Var(), right_.Var());
|
||||
}
|
||||
|
||||
public static bool operator true(ConstraintEquality eq)
|
||||
{
|
||||
return eq.IsTrue();
|
||||
}
|
||||
|
||||
public static bool operator false(ConstraintEquality eq)
|
||||
{
|
||||
return !eq.IsTrue();
|
||||
}
|
||||
|
||||
public static implicit operator Constraint(ConstraintEquality eq)
|
||||
{
|
||||
return eq.ToConstraint();
|
||||
}
|
||||
|
||||
public override IntVar Var()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeIsEqualVar(left_.Var(), right_.Var())
|
||||
: left_.solver().MakeIsDifferentVar(left_.Var(), right_.Var());
|
||||
}
|
||||
|
||||
public static implicit operator IntVar(ConstraintEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public static implicit operator IntExpr(ConstraintEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public override Solver solver()
|
||||
{
|
||||
return left_.solver();
|
||||
}
|
||||
|
||||
private IConstraintWithStatus left_;
|
||||
private IConstraintWithStatus right_;
|
||||
private bool equality_;
|
||||
return valCstPair.Cst;
|
||||
}
|
||||
|
||||
public static implicit operator IntVar(WrappedConstraint eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public static implicit operator IntExpr(WrappedConstraint eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public override Solver solver()
|
||||
{
|
||||
return this.Cst.solver();
|
||||
}
|
||||
|
||||
public override IntVar Var()
|
||||
{
|
||||
return Cst.Var();
|
||||
}
|
||||
}
|
||||
|
||||
public class IntExprEquality : BaseEquality
|
||||
{
|
||||
public IntExprEquality(IntExpr a, IntExpr b, bool equality)
|
||||
{
|
||||
this.left_ = a;
|
||||
this.right_ = b;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
bool IsTrue()
|
||||
{
|
||||
return (object)left_ == (object)right_ ? equality_ : !equality_;
|
||||
}
|
||||
|
||||
Constraint ToConstraint()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeEquality(left_.Var(), right_.Var())
|
||||
: left_.solver().MakeNonEquality(left_.Var(), right_.Var());
|
||||
}
|
||||
|
||||
public static bool operator true(IntExprEquality eq)
|
||||
{
|
||||
return eq.IsTrue();
|
||||
}
|
||||
|
||||
public static bool operator false(IntExprEquality eq)
|
||||
{
|
||||
return !eq.IsTrue();
|
||||
}
|
||||
|
||||
public static implicit operator Constraint(IntExprEquality eq)
|
||||
{
|
||||
return eq.ToConstraint();
|
||||
}
|
||||
|
||||
public override IntVar Var()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeIsEqualVar(left_, right_)
|
||||
: left_.solver().MakeIsDifferentVar(left_, right_);
|
||||
}
|
||||
|
||||
public static implicit operator IntVar(IntExprEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public static implicit operator IntExpr(IntExprEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public override Solver solver()
|
||||
{
|
||||
return left_.solver();
|
||||
}
|
||||
|
||||
private IntExpr left_;
|
||||
private IntExpr right_;
|
||||
private bool equality_;
|
||||
}
|
||||
|
||||
public class ConstraintEquality : BaseEquality
|
||||
{
|
||||
public ConstraintEquality(IConstraintWithStatus a, IConstraintWithStatus b, bool equality)
|
||||
{
|
||||
this.left_ = a;
|
||||
this.right_ = b;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
bool IsTrue()
|
||||
{
|
||||
return (object)left_ == (object)right_ ? equality_ : !equality_;
|
||||
}
|
||||
|
||||
Constraint ToConstraint()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeEquality(left_.Var(), right_.Var())
|
||||
: left_.solver().MakeNonEquality(left_.Var(), right_.Var());
|
||||
}
|
||||
|
||||
public static bool operator true(ConstraintEquality eq)
|
||||
{
|
||||
return eq.IsTrue();
|
||||
}
|
||||
|
||||
public static bool operator false(ConstraintEquality eq)
|
||||
{
|
||||
return !eq.IsTrue();
|
||||
}
|
||||
|
||||
public static implicit operator Constraint(ConstraintEquality eq)
|
||||
{
|
||||
return eq.ToConstraint();
|
||||
}
|
||||
|
||||
public override IntVar Var()
|
||||
{
|
||||
return equality_ ? left_.solver().MakeIsEqualVar(left_.Var(), right_.Var())
|
||||
: left_.solver().MakeIsDifferentVar(left_.Var(), right_.Var());
|
||||
}
|
||||
|
||||
public static implicit operator IntVar(ConstraintEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public static implicit operator IntExpr(ConstraintEquality eq)
|
||||
{
|
||||
return eq.Var();
|
||||
}
|
||||
|
||||
public override Solver solver()
|
||||
{
|
||||
return left_.solver();
|
||||
}
|
||||
|
||||
private IConstraintWithStatus left_;
|
||||
private IConstraintWithStatus right_;
|
||||
private bool equality_;
|
||||
}
|
||||
} // namespace Google.OrTools.ConstraintSolver
|
||||
|
||||
@@ -66,16 +66,16 @@ public final class CpIsFunCp {
|
||||
|
||||
// CP + IS + FUN = TRUE
|
||||
final IntVar sum1 =
|
||||
solver.makeSum(new IntVar[] {
|
||||
p, s, n,
|
||||
solver.makeProd(solver.makeSum(new IntVar[]{c, i, u}).var(), base).var(),
|
||||
solver.makeProd(f, base * base).var()}).var();
|
||||
final IntVar sum2 =
|
||||
solver.makeSum(new IntVar[] {
|
||||
e,
|
||||
solver.makeProd(u, base).var(),
|
||||
solver.makeProd(r, base * base).var(),
|
||||
solver.makeProd(t, base * base * base).var()}).var();
|
||||
solver
|
||||
.makeSum(new IntVar[] {p, s, n,
|
||||
solver.makeProd(solver.makeSum(new IntVar[] {c, i, u}).var(), base).var(),
|
||||
solver.makeProd(f, base * base).var()})
|
||||
.var();
|
||||
final IntVar sum2 = solver
|
||||
.makeSum(new IntVar[] {e, solver.makeProd(u, base).var(),
|
||||
solver.makeProd(r, base * base).var(),
|
||||
solver.makeProd(t, base * base * base).var()})
|
||||
.var();
|
||||
solver.addConstraint(solver.makeEquality(sum1, sum2));
|
||||
// [END constraints]
|
||||
|
||||
|
||||
@@ -43,12 +43,14 @@ public class SimpleRoutingProgram
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return Math.Abs(toNode - fromNode);
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return Math.Abs(toNode - fromNode);
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -146,12 +146,14 @@ public class TspCircuitBoard
|
||||
// Define cost of each arc.
|
||||
// [START transit_callback]
|
||||
long[,] distanceMatrix = ComputeEuclideanDistanceMatrix(data.Locations);
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return distanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return distanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// [START arc_cost]
|
||||
|
||||
@@ -88,12 +88,14 @@ public class TspCities
|
||||
// [END routing_model]
|
||||
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -93,12 +93,14 @@ public class TspDistanceMatrix
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -100,12 +100,14 @@ public class Vrp
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -120,12 +120,14 @@ public class VrpBreaks
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to time matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.TimeMatrix[fromNode, toNode] + data.ServiceTime[fromNode];
|
||||
});
|
||||
int transitCallbackIndex =
|
||||
routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to time matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.TimeMatrix[fromNode, toNode] + data.ServiceTime[fromNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -112,12 +112,14 @@ public class VrpCapacity
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
@@ -127,11 +129,14 @@ public class VrpCapacity
|
||||
|
||||
// Add Capacity constraint.
|
||||
// [START capacity_constraint]
|
||||
int demandCallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) => {
|
||||
// Convert from routing variable Index to demand NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
return data.Demands[fromNode];
|
||||
});
|
||||
int demandCallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// demand NodeIndex.
|
||||
var fromNode =
|
||||
manager.IndexToNode(fromIndex);
|
||||
return data.Demands[fromNode];
|
||||
});
|
||||
routing.AddDimensionWithVehicleCapacity(demandCallbackIndex, 0, // null capacity slack
|
||||
data.VehicleCapacities, // vehicle maximum capacities
|
||||
true, // start cumul to zero
|
||||
|
||||
@@ -127,12 +127,14 @@ public class VrpDropNodes
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
@@ -142,11 +144,14 @@ public class VrpDropNodes
|
||||
|
||||
// Add Capacity constraint.
|
||||
// [START capacity_constraint]
|
||||
int demandCallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) => {
|
||||
// Convert from routing variable Index to demand NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
return data.Demands[fromNode];
|
||||
});
|
||||
int demandCallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// demand NodeIndex.
|
||||
var fromNode =
|
||||
manager.IndexToNode(fromIndex);
|
||||
return data.Demands[fromNode];
|
||||
});
|
||||
routing.AddDimensionWithVehicleCapacity(demandCallbackIndex, 0, // null capacity slack
|
||||
data.VehicleCapacities, // vehicle maximum capacities
|
||||
true, // start cumul to zero
|
||||
|
||||
@@ -102,12 +102,14 @@ public class VrpGlobalSpan
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -109,12 +109,14 @@ public class InitialRoutes
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -140,8 +140,7 @@ public class VrpInitialRoutes {
|
||||
|
||||
// Setting first solution heuristic.
|
||||
// [START parameters]
|
||||
RoutingSearchParameters searchParameters =
|
||||
main.defaultRoutingSearchParameters().toBuilder().build();
|
||||
RoutingSearchParameters searchParameters = main.defaultRoutingSearchParameters();
|
||||
// [END parameters]
|
||||
|
||||
// Solve the problem.
|
||||
|
||||
@@ -108,12 +108,14 @@ public class VrpPickupDelivery
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -108,12 +108,14 @@ public class VrpPickupDeliveryFifo
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -107,12 +107,14 @@ public class VrpPickupDeliveryLifo
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -128,12 +128,14 @@ public class VrpResources
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.TimeMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.TimeMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -104,12 +104,14 @@ public class VrpStartsEnds
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.DistanceMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -123,12 +123,14 @@ public class VrpTimeWindows
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to time matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.TimeMatrix[fromNode, toNode];
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to time
|
||||
// matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return data.TimeMatrix[fromNode, toNode];
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -76,12 +76,14 @@ public class Vrp
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
|
||||
// Convert from routing variable Index to distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return 1;
|
||||
});
|
||||
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) =>
|
||||
{
|
||||
// Convert from routing variable Index to
|
||||
// distance matrix NodeIndex.
|
||||
var fromNode = manager.IndexToNode(fromIndex);
|
||||
var toNode = manager.IndexToNode(toIndex);
|
||||
return 1;
|
||||
});
|
||||
// [END transit_callback]
|
||||
|
||||
// Define cost of each arc.
|
||||
|
||||
@@ -24,79 +24,80 @@
|
||||
|
||||
namespace operations_research {
|
||||
|
||||
void NQueensCp(const int board_size) {
|
||||
// Instantiate the solver.
|
||||
// [START solver]
|
||||
Solver solver("N-Queens");
|
||||
// [END solver]
|
||||
void NQueensCp(const int board_size) {
|
||||
// Instantiate the solver.
|
||||
// [START solver]
|
||||
Solver solver("N-Queens");
|
||||
// [END solver]
|
||||
|
||||
// [START variables]
|
||||
std::vector<IntVar*> queens;
|
||||
queens.reserve(board_size);
|
||||
for (int i=0; i < board_size; ++i) {
|
||||
queens.push_back(solver.MakeIntVar(0, board_size - 1, absl::StrCat("x",i)));
|
||||
}
|
||||
// [END variables]
|
||||
|
||||
// Define constraints.
|
||||
// [START constraints]
|
||||
// The following sets the constraint that all queens are in different rows.
|
||||
solver.AddConstraint(solver.MakeAllDifferent(queens));
|
||||
|
||||
// All columns must be different because the indices of queens are all different.
|
||||
// No two queens can be on the same diagonal.
|
||||
std::vector<IntVar*> diag_1;
|
||||
diag_1.reserve(board_size);
|
||||
std::vector<IntVar*> diag_2;
|
||||
diag_2.reserve(board_size);
|
||||
for (int i=0; i < board_size; ++i) {
|
||||
diag_1.push_back(solver.MakeSum(queens[i], i)->Var());
|
||||
diag_2.push_back(solver.MakeSum(queens[i], -i)->Var());
|
||||
}
|
||||
solver.AddConstraint(solver.MakeAllDifferent(diag_1));
|
||||
solver.AddConstraint(solver.MakeAllDifferent(diag_2));
|
||||
// [END constraints]
|
||||
|
||||
// [START db]
|
||||
DecisionBuilder* const db = solver.MakePhase(
|
||||
queens, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE);
|
||||
// [END db]
|
||||
|
||||
// [START solve]
|
||||
// Iterates through the solutions, displaying each.
|
||||
int num_solutions = 0;
|
||||
|
||||
solver.NewSearch(db);
|
||||
while (solver.NextSolution()) {
|
||||
// Displays the solution just computed.
|
||||
LOG(INFO) << "Solution " << num_solutions;
|
||||
for (int i=0; i < board_size; ++i) {
|
||||
std::stringstream ss;
|
||||
for (int j=0; j < board_size; ++j) {
|
||||
if (queens[j]->Value() == i) {
|
||||
// There is a queen in column j, row i.
|
||||
ss << "Q";
|
||||
} else {
|
||||
ss << "_";
|
||||
}
|
||||
if (j != board_size-1) ss << " ";
|
||||
}
|
||||
LOG(INFO) << ss.str();
|
||||
}
|
||||
num_solutions++;
|
||||
}
|
||||
solver.EndSearch();
|
||||
// [END solve]
|
||||
|
||||
// Statistics.
|
||||
// [START statistics]
|
||||
LOG(INFO) << "Statistics";
|
||||
LOG(INFO) << " failures: " << solver.failures();
|
||||
LOG(INFO) << " branches: " << solver.branches();
|
||||
LOG(INFO) << " wall time: " << solver.wall_time() << " ms";
|
||||
LOG(INFO) << " Solutions found: " << num_solutions;
|
||||
// [END statistics]
|
||||
// [START variables]
|
||||
std::vector<IntVar*> queens;
|
||||
queens.reserve(board_size);
|
||||
for (int i = 0; i < board_size; ++i) {
|
||||
queens.push_back(
|
||||
solver.MakeIntVar(0, board_size - 1, absl::StrCat("x", i)));
|
||||
}
|
||||
// [END variables]
|
||||
|
||||
// Define constraints.
|
||||
// [START constraints]
|
||||
// The following sets the constraint that all queens are in different rows.
|
||||
solver.AddConstraint(solver.MakeAllDifferent(queens));
|
||||
|
||||
// All columns must be different because the indices of queens are all
|
||||
// different. No two queens can be on the same diagonal.
|
||||
std::vector<IntVar*> diag_1;
|
||||
diag_1.reserve(board_size);
|
||||
std::vector<IntVar*> diag_2;
|
||||
diag_2.reserve(board_size);
|
||||
for (int i = 0; i < board_size; ++i) {
|
||||
diag_1.push_back(solver.MakeSum(queens[i], i)->Var());
|
||||
diag_2.push_back(solver.MakeSum(queens[i], -i)->Var());
|
||||
}
|
||||
solver.AddConstraint(solver.MakeAllDifferent(diag_1));
|
||||
solver.AddConstraint(solver.MakeAllDifferent(diag_2));
|
||||
// [END constraints]
|
||||
|
||||
// [START db]
|
||||
DecisionBuilder* const db = solver.MakePhase(
|
||||
queens, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE);
|
||||
// [END db]
|
||||
|
||||
// [START solve]
|
||||
// Iterates through the solutions, displaying each.
|
||||
int num_solutions = 0;
|
||||
|
||||
solver.NewSearch(db);
|
||||
while (solver.NextSolution()) {
|
||||
// Displays the solution just computed.
|
||||
LOG(INFO) << "Solution " << num_solutions;
|
||||
for (int i = 0; i < board_size; ++i) {
|
||||
std::stringstream ss;
|
||||
for (int j = 0; j < board_size; ++j) {
|
||||
if (queens[j]->Value() == i) {
|
||||
// There is a queen in column j, row i.
|
||||
ss << "Q";
|
||||
} else {
|
||||
ss << "_";
|
||||
}
|
||||
if (j != board_size - 1) ss << " ";
|
||||
}
|
||||
LOG(INFO) << ss.str();
|
||||
}
|
||||
num_solutions++;
|
||||
}
|
||||
solver.EndSearch();
|
||||
// [END solve]
|
||||
|
||||
// Statistics.
|
||||
// [START statistics]
|
||||
LOG(INFO) << "Statistics";
|
||||
LOG(INFO) << " failures: " << solver.failures();
|
||||
LOG(INFO) << " branches: " << solver.branches();
|
||||
LOG(INFO) << " wall time: " << solver.wall_time() << " ms";
|
||||
LOG(INFO) << " Solutions found: " << num_solutions;
|
||||
// [END statistics]
|
||||
}
|
||||
|
||||
} // namespace operations_research
|
||||
|
||||
|
||||
@@ -13,156 +13,156 @@
|
||||
|
||||
namespace Google.OrTools.LinearSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class LinearConstraint
|
||||
public class LinearConstraint
|
||||
{
|
||||
public virtual String ToString()
|
||||
{
|
||||
public virtual String ToString()
|
||||
{
|
||||
return "LinearConstraint";
|
||||
}
|
||||
|
||||
public virtual Constraint Extract(Solver solver)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return "LinearConstraint";
|
||||
}
|
||||
|
||||
public class RangeConstraint : LinearConstraint
|
||||
public virtual Constraint Extract(Solver solver)
|
||||
{
|
||||
public RangeConstraint(LinearExpr expr, double lb, double ub)
|
||||
{
|
||||
this.expr_ = expr;
|
||||
this.lb_ = lb;
|
||||
this.ub_ = ub;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "" + lb_ + " <= " + expr_.ToString() + " <= " + ub_;
|
||||
}
|
||||
|
||||
public override Constraint Extract(Solver solver)
|
||||
{
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = expr_.Visit(coefficients);
|
||||
Constraint ct = solver.MakeConstraint(lb_ - constant, ub_ - constant);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
ct.SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
public static implicit operator bool(RangeConstraint ct)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private LinearExpr expr_;
|
||||
private double lb_;
|
||||
private double ub_;
|
||||
public class RangeConstraint : LinearConstraint
|
||||
{
|
||||
public RangeConstraint(LinearExpr expr, double lb, double ub)
|
||||
{
|
||||
this.expr_ = expr;
|
||||
this.lb_ = lb;
|
||||
this.ub_ = ub;
|
||||
}
|
||||
|
||||
public class Equality : LinearConstraint
|
||||
public override String ToString()
|
||||
{
|
||||
public Equality(LinearExpr left, LinearExpr right, bool equality)
|
||||
{
|
||||
this.left_ = left;
|
||||
this.right_ = right;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "" + left_.ToString() + " == " + right_.ToString();
|
||||
}
|
||||
|
||||
public override Constraint Extract(Solver solver)
|
||||
{
|
||||
if (!equality_)
|
||||
{
|
||||
throw new ArgumentException("Operator != not supported for LinearExpression");
|
||||
}
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = left_.Visit(coefficients);
|
||||
constant += right_.DoVisit(coefficients, -1);
|
||||
Constraint ct = solver.MakeConstraint(-constant, -constant);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
ct.SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
public static implicit operator bool(Equality ct)
|
||||
{
|
||||
return (object)ct.left_ == (object)ct.right_ ? ct.equality_ : !ct.equality_;
|
||||
}
|
||||
|
||||
private LinearExpr left_;
|
||||
private LinearExpr right_;
|
||||
private bool equality_;
|
||||
return "" + lb_ + " <= " + expr_.ToString() + " <= " + ub_;
|
||||
}
|
||||
|
||||
public class VarEquality : LinearConstraint
|
||||
public override Constraint Extract(Solver solver)
|
||||
{
|
||||
public VarEquality(Variable left, Variable right, bool equality)
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = expr_.Visit(coefficients);
|
||||
Constraint ct = solver.MakeConstraint(lb_ - constant, ub_ - constant);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
this.left_ = left;
|
||||
this.right_ = right;
|
||||
this.equality_ = equality;
|
||||
ct.SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "" + left_.Name() + " == " + right_.Name();
|
||||
}
|
||||
|
||||
public override Constraint Extract(Solver solver)
|
||||
{
|
||||
Constraint ct = solver.MakeConstraint(0.0, 0.0);
|
||||
ct.SetCoefficient(left_, 1.0);
|
||||
ct.SetCoefficient(right_, -1.0);
|
||||
return ct;
|
||||
}
|
||||
|
||||
public static implicit operator bool(VarEquality ct)
|
||||
{
|
||||
return (object)ct.left_ == (object)ct.right_ ? ct.equality_ : !ct.equality_;
|
||||
}
|
||||
|
||||
private Variable left_;
|
||||
private Variable right_;
|
||||
private bool equality_;
|
||||
return ct;
|
||||
}
|
||||
|
||||
// TODO(user): Try to move this code back to the .swig with @define macros.
|
||||
public partial class MPConstraintVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
public static implicit operator bool(RangeConstraint ct)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private LinearExpr expr_;
|
||||
private double lb_;
|
||||
private double ub_;
|
||||
}
|
||||
|
||||
public class Equality : LinearConstraint
|
||||
{
|
||||
public Equality(LinearExpr left, LinearExpr right, bool equality)
|
||||
{
|
||||
this.left_ = left;
|
||||
this.right_ = right;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "" + left_.ToString() + " == " + right_.ToString();
|
||||
}
|
||||
|
||||
public override Constraint Extract(Solver solver)
|
||||
{
|
||||
if (!equality_)
|
||||
{
|
||||
throw new ArgumentException("Operator != not supported for LinearExpression");
|
||||
}
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = left_.Visit(coefficients);
|
||||
constant += right_.DoVisit(coefficients, -1);
|
||||
Constraint ct = solver.MakeConstraint(-constant, -constant);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
ct.SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
public static implicit operator bool(Equality ct)
|
||||
{
|
||||
return (object)ct.left_ == (object)ct.right_ ? ct.equality_ : !ct.equality_;
|
||||
}
|
||||
|
||||
private LinearExpr left_;
|
||||
private LinearExpr right_;
|
||||
private bool equality_;
|
||||
}
|
||||
|
||||
public class VarEquality : LinearConstraint
|
||||
{
|
||||
public VarEquality(Variable left, Variable right, bool equality)
|
||||
{
|
||||
this.left_ = left;
|
||||
this.right_ = right;
|
||||
this.equality_ = equality;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "" + left_.Name() + " == " + right_.Name();
|
||||
}
|
||||
|
||||
public override Constraint Extract(Solver solver)
|
||||
{
|
||||
Constraint ct = solver.MakeConstraint(0.0, 0.0);
|
||||
ct.SetCoefficient(left_, 1.0);
|
||||
ct.SetCoefficient(right_, -1.0);
|
||||
return ct;
|
||||
}
|
||||
|
||||
public static implicit operator bool(VarEquality ct)
|
||||
{
|
||||
return (object)ct.left_ == (object)ct.right_ ? ct.equality_ : !ct.equality_;
|
||||
}
|
||||
|
||||
private Variable left_;
|
||||
private Variable right_;
|
||||
private bool equality_;
|
||||
}
|
||||
|
||||
// TODO(user): Try to move this code back to the .swig with @define macros.
|
||||
public partial class MPConstraintVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<Constraint>
|
||||
,
|
||||
System.Collections.Generic.IList<Constraint>
|
||||
#endif
|
||||
{
|
||||
// cast from C# MPConstraint array
|
||||
public static implicit operator MPConstraintVector(Constraint[] inVal)
|
||||
{
|
||||
// cast from C# MPConstraint array
|
||||
public static implicit operator MPConstraintVector(Constraint[] inVal)
|
||||
var outVal = new MPConstraintVector();
|
||||
foreach (Constraint element in inVal)
|
||||
{
|
||||
var outVal = new MPConstraintVector();
|
||||
foreach (Constraint element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# MPConstraint array
|
||||
public static implicit operator Constraint[](MPConstraintVector inVal)
|
||||
{
|
||||
var outVal = new Constraint[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# MPConstraint array
|
||||
public static implicit operator Constraint[](MPConstraintVector inVal)
|
||||
{
|
||||
var outVal = new Constraint[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools.LinearSolver
|
||||
|
||||
@@ -13,324 +13,324 @@
|
||||
|
||||
namespace Google.OrTools.LinearSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class LinearExpr
|
||||
public class LinearExpr
|
||||
{
|
||||
public virtual double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
public virtual double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public double Visit(Dictionary<Variable, double> coefficients)
|
||||
{
|
||||
return DoVisit(coefficients, 1.0);
|
||||
}
|
||||
public double Visit(Dictionary<Variable, double> coefficients)
|
||||
{
|
||||
return DoVisit(coefficients, 1.0);
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(LinearExpr a, double v)
|
||||
{
|
||||
return new SumCst(a, v);
|
||||
}
|
||||
public static LinearExpr operator +(LinearExpr a, double v)
|
||||
{
|
||||
return new SumCst(a, v);
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(double v, LinearExpr a)
|
||||
{
|
||||
return new SumCst(a, v);
|
||||
}
|
||||
public static LinearExpr operator +(double v, LinearExpr a)
|
||||
{
|
||||
return new SumCst(a, v);
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Sum(a, b);
|
||||
}
|
||||
public static LinearExpr operator +(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Sum(a, b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(LinearExpr a, double v)
|
||||
{
|
||||
return new SumCst(a, -v);
|
||||
}
|
||||
public static LinearExpr operator -(LinearExpr a, double v)
|
||||
{
|
||||
return new SumCst(a, -v);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(double v, LinearExpr a)
|
||||
{
|
||||
return new SumCst(new ProductCst(a, -1.0), v);
|
||||
}
|
||||
public static LinearExpr operator -(double v, LinearExpr a)
|
||||
{
|
||||
return new SumCst(new ProductCst(a, -1.0), v);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Sum(a, new ProductCst(b, -1.0));
|
||||
}
|
||||
public static LinearExpr operator -(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Sum(a, new ProductCst(b, -1.0));
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(LinearExpr a)
|
||||
{
|
||||
return new ProductCst(a, -1.0);
|
||||
}
|
||||
public static LinearExpr operator -(LinearExpr a)
|
||||
{
|
||||
return new ProductCst(a, -1.0);
|
||||
}
|
||||
|
||||
public static LinearExpr operator *(LinearExpr a, double v)
|
||||
{
|
||||
return new ProductCst(a, v);
|
||||
}
|
||||
public static LinearExpr operator *(LinearExpr a, double v)
|
||||
{
|
||||
return new ProductCst(a, v);
|
||||
}
|
||||
|
||||
public static LinearExpr operator /(LinearExpr a, double v)
|
||||
{
|
||||
return new ProductCst(a, 1 / v);
|
||||
}
|
||||
public static LinearExpr operator /(LinearExpr a, double v)
|
||||
{
|
||||
return new ProductCst(a, 1 / v);
|
||||
}
|
||||
|
||||
public static LinearExpr operator *(double v, LinearExpr a)
|
||||
{
|
||||
return new ProductCst(a, v);
|
||||
}
|
||||
public static LinearExpr operator *(double v, LinearExpr a)
|
||||
{
|
||||
return new ProductCst(a, v);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator ==(LinearExpr a, double v)
|
||||
{
|
||||
return new RangeConstraint(a, v, v);
|
||||
}
|
||||
public static RangeConstraint operator ==(LinearExpr a, double v)
|
||||
{
|
||||
return new RangeConstraint(a, v, v);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator ==(double v, LinearExpr a)
|
||||
{
|
||||
return new RangeConstraint(a, v, v);
|
||||
}
|
||||
public static RangeConstraint operator ==(double v, LinearExpr a)
|
||||
{
|
||||
return new RangeConstraint(a, v, v);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator !=(LinearExpr a, double v)
|
||||
{
|
||||
throw new ArgumentException("Operator != not supported for LinearExpression");
|
||||
}
|
||||
public static RangeConstraint operator !=(LinearExpr a, double v)
|
||||
{
|
||||
throw new ArgumentException("Operator != not supported for LinearExpression");
|
||||
}
|
||||
|
||||
public static RangeConstraint operator !=(double v, LinearExpr a)
|
||||
{
|
||||
throw new ArgumentException("Operator != not supported for LinearExpression");
|
||||
}
|
||||
public static RangeConstraint operator !=(double v, LinearExpr a)
|
||||
{
|
||||
throw new ArgumentException("Operator != not supported for LinearExpression");
|
||||
}
|
||||
|
||||
public static Equality operator ==(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Equality(a, b, true);
|
||||
}
|
||||
public static Equality operator ==(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Equality(a, b, true);
|
||||
}
|
||||
|
||||
public static Equality operator !=(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Equality(a, b, false);
|
||||
}
|
||||
public static Equality operator !=(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return new Equality(a, b, false);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(LinearExpr a, double v)
|
||||
{
|
||||
return new RangeConstraint(a, double.NegativeInfinity, v);
|
||||
}
|
||||
public static RangeConstraint operator <=(LinearExpr a, double v)
|
||||
{
|
||||
return new RangeConstraint(a, double.NegativeInfinity, v);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(LinearExpr a, double v)
|
||||
{
|
||||
return new RangeConstraint(a, v, double.PositiveInfinity);
|
||||
}
|
||||
public static RangeConstraint operator >=(LinearExpr a, double v)
|
||||
{
|
||||
return new RangeConstraint(a, v, double.PositiveInfinity);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return a - b <= 0;
|
||||
}
|
||||
public static RangeConstraint operator <=(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return a - b <= 0;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return a - b >= 0;
|
||||
}
|
||||
public static RangeConstraint operator >=(LinearExpr a, LinearExpr b)
|
||||
{
|
||||
return a - b >= 0;
|
||||
}
|
||||
|
||||
public static implicit operator LinearExpr(Variable a)
|
||||
public static implicit operator LinearExpr(Variable a)
|
||||
{
|
||||
return new VarWrapper(a);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LinearExprArrayHelper
|
||||
{
|
||||
public static LinearExpr Sum(this LinearExpr[] exprs)
|
||||
{
|
||||
return new SumArray(exprs);
|
||||
}
|
||||
|
||||
public static LinearExpr Sum(this Variable[] vars)
|
||||
{
|
||||
return new SumVarArray(vars);
|
||||
}
|
||||
}
|
||||
|
||||
// def __ge__(self, arg):
|
||||
// if isinstance(arg, (int, long, float)):
|
||||
// return LinearConstraint(self, arg, 1e308)
|
||||
// else:
|
||||
// return LinearConstraint(Sum(self, ProductCst(arg, -1)), 0.0, 1e308)
|
||||
|
||||
// def __le__(self, arg):
|
||||
// if isinstance(arg, (int, long, float)):
|
||||
// return LinearConstraint(self, -1e308, arg)
|
||||
// else:
|
||||
// return LinearConstraint(Sum(self, ProductCst(arg, -1)), -1e308, 0.0)
|
||||
|
||||
class ProductCst : LinearExpr
|
||||
{
|
||||
public ProductCst(LinearExpr expr, double coeff)
|
||||
{
|
||||
this.coeff_ = coeff;
|
||||
this.expr_ = expr;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "(" + expr_.ToString() + " * " + coeff_ + ")";
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
double current_multiplier = multiplier * coeff_;
|
||||
if (current_multiplier != 0.0)
|
||||
{
|
||||
return new VarWrapper(a);
|
||||
return expr_.DoVisit(coefficients, current_multiplier);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LinearExprArrayHelper
|
||||
{
|
||||
public static LinearExpr Sum(this LinearExpr[] exprs)
|
||||
{
|
||||
return new SumArray(exprs);
|
||||
}
|
||||
private LinearExpr expr_;
|
||||
private double coeff_;
|
||||
}
|
||||
|
||||
public static LinearExpr Sum(this Variable[] vars)
|
||||
class SumCst : LinearExpr
|
||||
{
|
||||
public SumCst(LinearExpr expr, double coeff)
|
||||
{
|
||||
this.coeff_ = coeff;
|
||||
this.expr_ = expr;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "(" + expr_.ToString() + " + " + coeff_ + ")";
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
return new SumVarArray(vars);
|
||||
return coeff_ * multiplier + expr_.DoVisit(coefficients, multiplier);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
// def __ge__(self, arg):
|
||||
// if isinstance(arg, (int, long, float)):
|
||||
// return LinearConstraint(self, arg, 1e308)
|
||||
// else:
|
||||
// return LinearConstraint(Sum(self, ProductCst(arg, -1)), 0.0, 1e308)
|
||||
private LinearExpr expr_;
|
||||
private double coeff_;
|
||||
}
|
||||
|
||||
// def __le__(self, arg):
|
||||
// if isinstance(arg, (int, long, float)):
|
||||
// return LinearConstraint(self, -1e308, arg)
|
||||
// else:
|
||||
// return LinearConstraint(Sum(self, ProductCst(arg, -1)), -1e308, 0.0)
|
||||
|
||||
class ProductCst : LinearExpr
|
||||
class VarWrapper : LinearExpr
|
||||
{
|
||||
public VarWrapper(Variable var)
|
||||
{
|
||||
public ProductCst(LinearExpr expr, double coeff)
|
||||
{
|
||||
this.coeff_ = coeff;
|
||||
this.expr_ = expr;
|
||||
}
|
||||
this.var_ = var;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "(" + expr_.ToString() + " * " + coeff_ + ")";
|
||||
}
|
||||
public override String ToString()
|
||||
{
|
||||
return var_.Name();
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
double current_multiplier = multiplier * coeff_;
|
||||
if (current_multiplier != 0.0)
|
||||
if (coefficients.ContainsKey(var_))
|
||||
{
|
||||
return expr_.DoVisit(coefficients, current_multiplier);
|
||||
coefficients[var_] += multiplier;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
coefficients[var_] = multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
private LinearExpr expr_;
|
||||
private double coeff_;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
class SumCst : LinearExpr
|
||||
private Variable var_;
|
||||
}
|
||||
|
||||
class Sum : LinearExpr
|
||||
{
|
||||
public Sum(LinearExpr left, LinearExpr right)
|
||||
{
|
||||
public SumCst(LinearExpr expr, double coeff)
|
||||
{
|
||||
this.coeff_ = coeff;
|
||||
this.expr_ = expr;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "(" + expr_.ToString() + " + " + coeff_ + ")";
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
return coeff_ * multiplier + expr_.DoVisit(coefficients, multiplier);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private LinearExpr expr_;
|
||||
private double coeff_;
|
||||
this.left_ = left;
|
||||
this.right_ = right;
|
||||
}
|
||||
|
||||
class VarWrapper : LinearExpr
|
||||
public override String ToString()
|
||||
{
|
||||
public VarWrapper(Variable var)
|
||||
{
|
||||
this.var_ = var;
|
||||
}
|
||||
return "(" + left_.ToString() + " + " + right_.ToString() + ")";
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
return var_.Name();
|
||||
return left_.DoVisit(coefficients, multiplier) + right_.DoVisit(coefficients, multiplier);
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
else
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private LinearExpr left_;
|
||||
private LinearExpr right_;
|
||||
}
|
||||
|
||||
public class SumArray : LinearExpr
|
||||
{
|
||||
public SumArray(LinearExpr[] array)
|
||||
{
|
||||
this.array_ = array;
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
double constant = 0.0;
|
||||
foreach (LinearExpr expr in array_)
|
||||
{
|
||||
if (coefficients.ContainsKey(var_))
|
||||
constant += expr.DoVisit(coefficients, multiplier);
|
||||
}
|
||||
return constant;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private LinearExpr[] array_;
|
||||
}
|
||||
|
||||
public class SumVarArray : LinearExpr
|
||||
{
|
||||
public SumVarArray(Variable[] array)
|
||||
{
|
||||
this.array_ = array;
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
foreach (Variable var in array_)
|
||||
{
|
||||
if (coefficients.ContainsKey(var))
|
||||
{
|
||||
coefficients[var_] += multiplier;
|
||||
coefficients[var] += multiplier;
|
||||
}
|
||||
else
|
||||
{
|
||||
coefficients[var_] = multiplier;
|
||||
coefficients[var] = multiplier;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
private Variable var_;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
class Sum : LinearExpr
|
||||
{
|
||||
public Sum(LinearExpr left, LinearExpr right)
|
||||
{
|
||||
this.left_ = left;
|
||||
this.right_ = right;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "(" + left_.ToString() + " + " + right_.ToString() + ")";
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
return left_.DoVisit(coefficients, multiplier) + right_.DoVisit(coefficients, multiplier);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private LinearExpr left_;
|
||||
private LinearExpr right_;
|
||||
}
|
||||
|
||||
public class SumArray : LinearExpr
|
||||
{
|
||||
public SumArray(LinearExpr[] array)
|
||||
{
|
||||
this.array_ = array;
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
double constant = 0.0;
|
||||
foreach (LinearExpr expr in array_)
|
||||
{
|
||||
constant += expr.DoVisit(coefficients, multiplier);
|
||||
}
|
||||
return constant;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private LinearExpr[] array_;
|
||||
}
|
||||
|
||||
public class SumVarArray : LinearExpr
|
||||
{
|
||||
public SumVarArray(Variable[] array)
|
||||
{
|
||||
this.array_ = array;
|
||||
}
|
||||
|
||||
public override double DoVisit(Dictionary<Variable, double> coefficients, double multiplier)
|
||||
{
|
||||
if (multiplier != 0.0)
|
||||
{
|
||||
foreach (Variable var in array_)
|
||||
{
|
||||
if (coefficients.ContainsKey(var))
|
||||
{
|
||||
coefficients[var] += multiplier;
|
||||
}
|
||||
else
|
||||
{
|
||||
coefficients[var] = multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
private Variable[] array_;
|
||||
}
|
||||
private Variable[] array_;
|
||||
}
|
||||
} // namespace Google.OrTools.LinearSolver
|
||||
|
||||
@@ -13,217 +13,217 @@
|
||||
|
||||
namespace Google.OrTools.LinearSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Patch the MPSolver class to:
|
||||
// - support custom versions of the array-based APIs (MakeVarArray, etc).
|
||||
// - customize the construction, and the OptimizationProblemType enum.
|
||||
// - support the natural language API.
|
||||
public partial class Solver
|
||||
// Patch the MPSolver class to:
|
||||
// - support custom versions of the array-based APIs (MakeVarArray, etc).
|
||||
// - customize the construction, and the OptimizationProblemType enum.
|
||||
// - support the natural language API.
|
||||
public partial class Solver
|
||||
{
|
||||
public Variable[] MakeVarArray(int count, double lb, double ub, bool integer)
|
||||
{
|
||||
public Variable[] MakeVarArray(int count, double lb, double ub, bool integer)
|
||||
Variable[] array = new Variable[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
Variable[] array = new Variable[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
array[i] = MakeVar(lb, ub, integer, "");
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public Variable[] MakeVarArray(int count, double lb, double ub, bool integer, string var_name)
|
||||
{
|
||||
Variable[] array = new Variable[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
array[i] = MakeVar(lb, ub, integer, var_name + i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public Variable[,] MakeVarMatrix(int rows, int cols, double lb, double ub, bool integer)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeVar(lb, ub, integer, "");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeVarMatrix(int rows, int cols, double lb, double ub, bool integer, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeVar(lb, ub, integer, var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[] MakeNumVarArray(int count, double lb, double ub)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, false);
|
||||
}
|
||||
|
||||
public Variable[] MakeNumVarArray(int count, double lb, double ub, string var_name)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, false, var_name);
|
||||
}
|
||||
|
||||
public Variable[,] MakeNumVarMatrix(int rows, int cols, double lb, double ub)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeNumVar(lb, ub, "");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeNumVarMatrix(int rows, int cols, double lb, double ub, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeNumVar(lb, ub, var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[] MakeIntVarArray(int count, double lb, double ub)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, true);
|
||||
}
|
||||
|
||||
public Variable[] MakeIntVarArray(int count, double lb, double ub, string var_name)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, true, var_name);
|
||||
}
|
||||
|
||||
public Variable[,] MakeIntVarMatrix(int rows, int cols, double lb, double ub)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeIntVar(lb, ub, "");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeIntVarMatrix(int rows, int cols, double lb, double ub, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeIntVar(lb, ub, var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[] MakeBoolVarArray(int count)
|
||||
{
|
||||
return MakeVarArray(count, 0.0, 1.0, true);
|
||||
}
|
||||
|
||||
public Variable[] MakeBoolVarArray(int count, string var_name)
|
||||
{
|
||||
return MakeVarArray(count, 0.0, 1.0, true, var_name);
|
||||
}
|
||||
|
||||
public Variable[,] MakeBoolVarMatrix(int rows, int cols)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeBoolVar("");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeBoolVarMatrix(int rows, int cols, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeBoolVar(var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Constraint Add(LinearConstraint constraint)
|
||||
{
|
||||
return constraint.Extract(this);
|
||||
}
|
||||
|
||||
public void Minimize(LinearExpr expr)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMinimization();
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = expr.Visit(coefficients);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
Objective().SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
Objective().SetOffset(constant);
|
||||
}
|
||||
|
||||
public void Maximize(LinearExpr expr)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMaximization();
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = expr.Visit(coefficients);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
Objective().SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
Objective().SetOffset(constant);
|
||||
}
|
||||
|
||||
public void Minimize(Variable var)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMinimization();
|
||||
Objective().SetCoefficient(var, 1.0);
|
||||
}
|
||||
|
||||
public void Maximize(Variable var)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMaximization();
|
||||
Objective().SetCoefficient(var, 1.0);
|
||||
array[i] = MakeVar(lb, ub, integer, "");
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public Variable[] MakeVarArray(int count, double lb, double ub, bool integer, string var_name)
|
||||
{
|
||||
Variable[] array = new Variable[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
array[i] = MakeVar(lb, ub, integer, var_name + i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public Variable[,] MakeVarMatrix(int rows, int cols, double lb, double ub, bool integer)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeVar(lb, ub, integer, "");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeVarMatrix(int rows, int cols, double lb, double ub, bool integer, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeVar(lb, ub, integer, var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[] MakeNumVarArray(int count, double lb, double ub)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, false);
|
||||
}
|
||||
|
||||
public Variable[] MakeNumVarArray(int count, double lb, double ub, string var_name)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, false, var_name);
|
||||
}
|
||||
|
||||
public Variable[,] MakeNumVarMatrix(int rows, int cols, double lb, double ub)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeNumVar(lb, ub, "");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeNumVarMatrix(int rows, int cols, double lb, double ub, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeNumVar(lb, ub, var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[] MakeIntVarArray(int count, double lb, double ub)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, true);
|
||||
}
|
||||
|
||||
public Variable[] MakeIntVarArray(int count, double lb, double ub, string var_name)
|
||||
{
|
||||
return MakeVarArray(count, lb, ub, true, var_name);
|
||||
}
|
||||
|
||||
public Variable[,] MakeIntVarMatrix(int rows, int cols, double lb, double ub)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeIntVar(lb, ub, "");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeIntVarMatrix(int rows, int cols, double lb, double ub, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeIntVar(lb, ub, var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[] MakeBoolVarArray(int count)
|
||||
{
|
||||
return MakeVarArray(count, 0.0, 1.0, true);
|
||||
}
|
||||
|
||||
public Variable[] MakeBoolVarArray(int count, string var_name)
|
||||
{
|
||||
return MakeVarArray(count, 0.0, 1.0, true, var_name);
|
||||
}
|
||||
|
||||
public Variable[,] MakeBoolVarMatrix(int rows, int cols)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
matrix[i, j] = MakeBoolVar("");
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Variable[,] MakeBoolVarMatrix(int rows, int cols, string name)
|
||||
{
|
||||
Variable[,] matrix = new Variable[rows, cols];
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
string var_name = name + "[" + i + ", " + j + "]";
|
||||
matrix[i, j] = MakeBoolVar(var_name);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public Constraint Add(LinearConstraint constraint)
|
||||
{
|
||||
return constraint.Extract(this);
|
||||
}
|
||||
|
||||
public void Minimize(LinearExpr expr)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMinimization();
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = expr.Visit(coefficients);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
Objective().SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
Objective().SetOffset(constant);
|
||||
}
|
||||
|
||||
public void Maximize(LinearExpr expr)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMaximization();
|
||||
Dictionary<Variable, double> coefficients = new Dictionary<Variable, double>();
|
||||
double constant = expr.Visit(coefficients);
|
||||
foreach (KeyValuePair<Variable, double> pair in coefficients)
|
||||
{
|
||||
Objective().SetCoefficient(pair.Key, pair.Value);
|
||||
}
|
||||
Objective().SetOffset(constant);
|
||||
}
|
||||
|
||||
public void Minimize(Variable var)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMinimization();
|
||||
Objective().SetCoefficient(var, 1.0);
|
||||
}
|
||||
|
||||
public void Maximize(Variable var)
|
||||
{
|
||||
Objective().Clear();
|
||||
Objective().SetMaximization();
|
||||
Objective().SetCoefficient(var, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Google.OrTools.LinearSolver
|
||||
|
||||
@@ -13,209 +13,209 @@
|
||||
|
||||
namespace Google.OrTools.LinearSolver
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Patch the MPVariable class to support the natural language API.
|
||||
public partial class Variable
|
||||
// Patch the MPVariable class to support the natural language API.
|
||||
public partial class Variable
|
||||
{
|
||||
public static LinearExpr operator +(Variable a, double v)
|
||||
{
|
||||
public static LinearExpr operator +(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) + v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(double v, Variable a)
|
||||
{
|
||||
return a + v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) + b;
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) + new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(LinearExpr a, Variable b)
|
||||
{
|
||||
return a + new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) - v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(double v, Variable a)
|
||||
{
|
||||
return v - new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) - b;
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(LinearExpr a, Variable b)
|
||||
{
|
||||
return a - new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) - new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a)
|
||||
{
|
||||
return -new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static LinearExpr operator *(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) * v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator /(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) / v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator *(double v, Variable a)
|
||||
{
|
||||
return v * new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator ==(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) == v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator ==(double v, Variable a)
|
||||
{
|
||||
return v == new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator !=(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) != v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator !=(double v, Variable a)
|
||||
{
|
||||
return new VarWrapper(a) != v;
|
||||
}
|
||||
|
||||
public static Equality operator ==(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) == b;
|
||||
}
|
||||
|
||||
public static Equality operator ==(LinearExpr a, Variable b)
|
||||
{
|
||||
return a == new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static VarEquality operator ==(Variable a, Variable b)
|
||||
{
|
||||
return new VarEquality(a, b, true);
|
||||
}
|
||||
|
||||
public static Equality operator !=(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) != b;
|
||||
}
|
||||
|
||||
public static Equality operator !=(LinearExpr a, Variable b)
|
||||
{
|
||||
return a != new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static VarEquality operator !=(Variable a, Variable b)
|
||||
{
|
||||
return new VarEquality(a, b, false);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) <= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) >= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(double v, Variable a)
|
||||
{
|
||||
return new VarWrapper(a) >= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(double v, Variable a)
|
||||
{
|
||||
return new VarWrapper(a) <= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) <= b;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) >= b;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) <= new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) >= new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(LinearExpr a, Variable b)
|
||||
{
|
||||
return a <= new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(LinearExpr a, Variable b)
|
||||
{
|
||||
return a >= new VarWrapper(b);
|
||||
}
|
||||
return new VarWrapper(a) + v;
|
||||
}
|
||||
|
||||
// TODO(user): Try to move this code back to the .swig with @define macros.
|
||||
public partial class MPVariableVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
public static LinearExpr operator +(double v, Variable a)
|
||||
{
|
||||
return a + v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) + b;
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) + new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator +(LinearExpr a, Variable b)
|
||||
{
|
||||
return a + new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) - v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(double v, Variable a)
|
||||
{
|
||||
return v - new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) - b;
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(LinearExpr a, Variable b)
|
||||
{
|
||||
return a - new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) - new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static LinearExpr operator -(Variable a)
|
||||
{
|
||||
return -new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static LinearExpr operator *(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) * v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator /(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) / v;
|
||||
}
|
||||
|
||||
public static LinearExpr operator *(double v, Variable a)
|
||||
{
|
||||
return v * new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator ==(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) == v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator ==(double v, Variable a)
|
||||
{
|
||||
return v == new VarWrapper(a);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator !=(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) != v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator !=(double v, Variable a)
|
||||
{
|
||||
return new VarWrapper(a) != v;
|
||||
}
|
||||
|
||||
public static Equality operator ==(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) == b;
|
||||
}
|
||||
|
||||
public static Equality operator ==(LinearExpr a, Variable b)
|
||||
{
|
||||
return a == new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static VarEquality operator ==(Variable a, Variable b)
|
||||
{
|
||||
return new VarEquality(a, b, true);
|
||||
}
|
||||
|
||||
public static Equality operator !=(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) != b;
|
||||
}
|
||||
|
||||
public static Equality operator !=(LinearExpr a, Variable b)
|
||||
{
|
||||
return a != new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static VarEquality operator !=(Variable a, Variable b)
|
||||
{
|
||||
return new VarEquality(a, b, false);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) <= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(Variable a, double v)
|
||||
{
|
||||
return new VarWrapper(a) >= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(double v, Variable a)
|
||||
{
|
||||
return new VarWrapper(a) >= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(double v, Variable a)
|
||||
{
|
||||
return new VarWrapper(a) <= v;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) <= b;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(Variable a, LinearExpr b)
|
||||
{
|
||||
return new VarWrapper(a) >= b;
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) <= new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(Variable a, Variable b)
|
||||
{
|
||||
return new VarWrapper(a) >= new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator <=(LinearExpr a, Variable b)
|
||||
{
|
||||
return a <= new VarWrapper(b);
|
||||
}
|
||||
|
||||
public static RangeConstraint operator >=(LinearExpr a, Variable b)
|
||||
{
|
||||
return a >= new VarWrapper(b);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(user): Try to move this code back to the .swig with @define macros.
|
||||
public partial class MPVariableVector : IDisposable,
|
||||
System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
,
|
||||
System.Collections.Generic.IList<Variable>
|
||||
,
|
||||
System.Collections.Generic.IList<Variable>
|
||||
#endif
|
||||
{
|
||||
// cast from C# MPVariable array
|
||||
public static implicit operator MPVariableVector(Variable[] inVal)
|
||||
{
|
||||
// cast from C# MPVariable array
|
||||
public static implicit operator MPVariableVector(Variable[] inVal)
|
||||
var outVal = new MPVariableVector();
|
||||
foreach (Variable element in inVal)
|
||||
{
|
||||
var outVal = new MPVariableVector();
|
||||
foreach (Variable element in inVal)
|
||||
{
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# MPVariable array
|
||||
public static implicit operator Variable[](MPVariableVector inVal)
|
||||
{
|
||||
var outVal = new Variable[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
outVal.Add(element);
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# MPVariable array
|
||||
public static implicit operator Variable[](MPVariableVector inVal)
|
||||
{
|
||||
var outVal = new Variable[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Google.OrTools.LinearSolver
|
||||
|
||||
@@ -14,54 +14,54 @@
|
||||
namespace Google.OrTools
|
||||
{
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class NestedArrayHelper
|
||||
public static class NestedArrayHelper
|
||||
{
|
||||
public static T[] GetFlatArray<T>(T[][] arr)
|
||||
{
|
||||
public static T[] GetFlatArray<T>(T[][] arr)
|
||||
int flatLength = 0;
|
||||
for (var i = 0; i < arr.GetLength(0); i++)
|
||||
flatLength += arr[i].GetLength(0);
|
||||
|
||||
int idx = 0;
|
||||
T[] flat = new T[flatLength];
|
||||
|
||||
for (int i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
int flatLength = 0;
|
||||
for (var i = 0; i < arr.GetLength(0); i++)
|
||||
flatLength += arr[i].GetLength(0);
|
||||
|
||||
int idx = 0;
|
||||
T[] flat = new T[flatLength];
|
||||
|
||||
for (int i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr[i].GetLength(0); j++)
|
||||
flat[idx++] = arr[i][j];
|
||||
}
|
||||
|
||||
return flat;
|
||||
for (int j = 0; j < arr[i].GetLength(0); j++)
|
||||
flat[idx++] = arr[i][j];
|
||||
}
|
||||
|
||||
public static T[] GetFlatArrayFromMatrix<T>(T[,] arr)
|
||||
{
|
||||
int flatLength = arr.GetLength(0) * arr.GetLength(1);
|
||||
|
||||
int idx = 0;
|
||||
T[] flat = new T[flatLength];
|
||||
|
||||
for (int i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr.GetLength(1); j++)
|
||||
flat[idx++] = arr[i, j];
|
||||
}
|
||||
|
||||
return flat;
|
||||
}
|
||||
|
||||
public static int[] GetArraySecondSize<T>(T[][] arr)
|
||||
{
|
||||
var result = new int[arr.GetLength(0)];
|
||||
for (var i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
if (arr[i] != null)
|
||||
result[i] = arr[i].Length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return flat;
|
||||
}
|
||||
|
||||
public static T[] GetFlatArrayFromMatrix<T>(T[,] arr)
|
||||
{
|
||||
int flatLength = arr.GetLength(0) * arr.GetLength(1);
|
||||
|
||||
int idx = 0;
|
||||
T[] flat = new T[flatLength];
|
||||
|
||||
for (int i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr.GetLength(1); j++)
|
||||
flat[idx++] = arr[i, j];
|
||||
}
|
||||
|
||||
return flat;
|
||||
}
|
||||
|
||||
public static int[] GetArraySecondSize<T>(T[][] arr)
|
||||
{
|
||||
var result = new int[arr.GetLength(0)];
|
||||
for (var i = 0; i < arr.GetLength(0); i++)
|
||||
{
|
||||
if (arr[i] != null)
|
||||
result[i] = arr[i].Length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
namespace Google.OrTools
|
||||
{
|
||||
|
||||
using System;
|
||||
using Google.Protobuf;
|
||||
using System;
|
||||
using Google.Protobuf;
|
||||
|
||||
public static class ProtoHelper
|
||||
public static class ProtoHelper
|
||||
{
|
||||
public static byte[] ProtoToByteArray(IMessage message)
|
||||
{
|
||||
public static byte[] ProtoToByteArray(IMessage message)
|
||||
{
|
||||
int size = message.CalculateSize();
|
||||
byte[] buffer = new byte[size];
|
||||
CodedOutputStream output = new CodedOutputStream(buffer);
|
||||
message.WriteTo(output);
|
||||
return buffer;
|
||||
}
|
||||
int size = message.CalculateSize();
|
||||
byte[] buffer = new byte[size];
|
||||
CodedOutputStream output = new CodedOutputStream(buffer);
|
||||
message.WriteTo(output);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools
|
||||
|
||||
Reference in New Issue
Block a user