本文整理汇总了C#中Cream.Network类的典型用法代码示例。如果您正苦于以下问题:C# Network类的具体用法?C# Network怎么用?C# Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Network类属于Cream命名空间,在下文中一共展示了Network类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Network net = new Network();
IntVariable[] A = new IntVariable[6];
for (int j=0; j< 6; j++)
{
IntDomain d = new IntDomain(1, 9);
A[j] = new IntVariable(net);
A[j].Domain = d;
Trail trail = new Trail();
}
((A[4].Multiply(10).Add(A[5])).Multiply(A[0])).Add(
((A[1].Multiply(10).Add(A[2])).Multiply(A[3]))).Equals(
(A[1].Multiply(10).Add(A[2])).Multiply(A[4].Multiply(10).Add(A[5])));
new NotEquals(net, A);
Solver solver = new DefaultSolver(net);
int i = 0;
for (solver.Start(); solver.WaitNext(); solver.Resume())
{
Solution solution = solver.Solution;
Console.Out.WriteLine();
Console.Out.WriteLine(solution.GetIntValue(A[0]) + " " + solution.GetIntValue(A[3]));
Console.Out.WriteLine("-- + -- = 1");
Console.Out.WriteLine(solution.GetIntValue(A[1])+""+solution.GetIntValue(A[2])+" "+
solution.GetIntValue(A[4]) + solution.GetIntValue(A[5]));
Console.Out.WriteLine("=========");
i++;
}
Console.Out.WriteLine("There are {0} solutions",i);
solver.Stop();
Console.In.ReadLine();
//------------------------------------------------------------------------------------------
}
示例2: Constraint
/// <summary> Constructor.
/// (for invocation by subclass constructors, typically implicit)
/// </summary>
protected internal Constraint(Network net)
{
Network = net;
Index = -1;
Network.ADD(this);
CType = ConstraintTypes.Hard;
}
示例3: Relation
public Relation(Network net, Variable v0, bool[][] rel, Variable v1, ConstraintTypes cType, int weight)
: base(net, cType, weight)
{
_rel = rel;
_v0 = v0;
_v1 = v1;
}
示例4: queens
internal void queens(int n)
{
var c = 0;
var net = new Network();
var q = new IntVariable[n];
var u = new IntVariable[n];
var d = new IntVariable[n];
for (var i = 0; i < n; ++i)
{
q[i] = new IntVariable(net, 1, n);
u[i] = q[i].Add(i);
d[i] = q[i].Subtract(i);
}
new NotEquals(net, q);
new NotEquals(net, u);
new NotEquals(net, d);
Solver solver = new DefaultSolver(net);
for (solver.Start(); solver.WaitNext(); solver.Resume())
{
Solution solution = solver.Solution;
sol[c] = new int[8];
for (int i = 0; i < n; i++)
{
var s = solution.GetIntValue(q[i]);
sol[c][i] = solution.GetIntValue(q[i]);
}
c++;
}
solver.Stop();
}
示例5: Element
public Element(Network net, Variable v0, Variable v1, Variable[] v, ConstraintTypes cType, int weight)
: base(net, cType, weight)
{
_v0 = v0;
_v1 = v1;
_v = (Variable[])v.Clone();
}
示例6: Semantics
public Semantics(Cell baseCell, Dictionary<string, Cell> cells,
Network network, SpreadSheet spreadSheet)
{
_baseCell = baseCell;
_cells = cells;
_network = network;
_spreadSheet = spreadSheet;
}
示例7: Sequential
public Sequential(Network net, Variable[] v, int[] l, ConstraintTypes cType, int weight)
: base(net, cType, weight)
{
_v = new Variable[v.Length];
v.CopyTo(_v, 0);
_l = new int[l.Length];
l.CopyTo(_l, 0);
}
示例8: maxExample
internal static void maxExample()
{
var net = new Network();
var x = new IntVariable(net, -1, 1, "x");
var y = new IntVariable(net, -1, 1, "y");
var z = x.Max(y);
z.Name ="z";
runExample(net, Solver.Default);
}
示例9: absExample
internal static void absExample()
{
var net = new Network();
var x = new IntVariable(net, -3, 2, "x");
var y = x.Abs();
y.NotEquals(2);
y.Name ="y";
runExample(net, Solver.Default);
}
示例10: Variable
/// <summary> Constructs a variable of the network
/// with an initial domain <tt>d</tt>
/// and a name specified by the parameter <tt>name</tt>.
/// When the parameter <tt>name</tt> is <tt>null</tt>,
/// default names (<tt>v1</tt>, <tt>v2</tt>, and so on) are used.
/// </summary>
/// <param name="net">the network
/// </param>
/// <param name="d">the initial domain
/// </param>
/// <param name="name">the name of the variable, or <tt>null</tt> for a default name
/// </param>
public Variable(Network net, Domain d, String name)
{
Network = net;
Domain = d;
_modified = true;
_watch = false;
Name = name ?? "v" + (_count++);
Network.ADD(this);
}
示例11: pp
internal static void pp()
{
Network net = new Network();
// number of materials
int m = 3;
// limit of each material
int[] limit = new int[] { 1650, 1400, 1800 };
// number of products
int n = 2;
// profit of each product
int[] p = new int[] { 5, 4 };
// amount of materials required to make each product
int[][] a = new int[][] { new int[] { 15, 10, 9 }, new int[] { 11, 14, 20 } };
// initialize variables for products
IntVariable[] x = new IntVariable[n];
for (int j = 0; j < n; j++)
{
x[j] = new IntVariable(net);
x[j].Ge(0);
}
// generate constraits of limiting materials
for (int i = 0; i < m; i++)
{
IntVariable sum = new IntVariable(net, 0);
for (int j = 0; j < n; j++)
{
sum = sum.Add(x[j].Multiply(a[j][i]));
}
sum.Le(limit[i]);
}
// total profit
IntVariable profit = new IntVariable(net, 0);
for (int j = 0; j < n; j++)
{
profit = profit.Add(x[j].Multiply(p[j]));
}
// maximize the total profit
net.Objective = profit;
// iteratively find a better solution until the optimal solution is found
Solver solver = new DefaultSolver(net, Solver.Maximize | Solver.Better);
for (solver.Start(); solver.WaitNext(); solver.Resume())
{
Solution solution = solver.Solution;
Console.WriteLine(solver.GetCount());
Console.Out.WriteLine("Profit = " + solution.GetIntValue(profit));
for (int j = 0; j < n; j++)
{
Console.Out.WriteLine("x[" + j + "]=" + solution.GetIntValue(x[j]));
}
Console.Out.WriteLine();
}
solver.Stop();
Console.ReadLine();
}
示例12: Code
public Code(Network network)
{
System.Collections.IList constraints = network.Constraints;
conditions = new Condition[constraints.Count];
for (var i = 0; i < conditions.Length; i++)
{
var c = network.GetConstraint(i);
conditions[i] = c.ExtractCondition();
}
}
示例13: minimizeExample
internal static void minimizeExample()
{
var net = new Network();
var x = new IntVariable(net, 1, 10, "x");
var y = new IntVariable(net, 1, 10, "y");
// x + y >= 10
x.Add(y).Ge(10);
// z = max(x, y)
var z = x.Max(y);
z.Name ="z";
// minimize z
net.Objective = z;
runExample(net, Solver.Minimize | Solver.Better);
}
示例14: elementExample
internal static void elementExample()
{
var net = new Network();
var x = new IntVariable(net, "x");
var i = new IntVariable(net, "i");
const int n = 4;
var v = new IntVariable[n];
//var ran = new Random(1000);
for (var j = 0; j < n; j++)
{
//v[j] = new IntVariable(net, ran.Next(200));
v[j] = new IntVariable(net, 10 * (j + 1)+2);
}
new Element(net, x, i, v);
runExample(net, Solver.Default);
}
示例15: DefaultSolver
/// <summary>
/// Initializes a new instance of the <see cref="DefaultSolver"/> class. Constructs a branch-and-bound solver for the given network, options, and name.
/// </summary>
/// <param name="network">
/// the constraint network
/// </param>
/// <param name="options">
/// the options for search strategy, or Default for default search strategy
/// </param>
/// <param name="name">
/// the name of the solver, or <tt>null</tt> for a default name
/// </param>
public DefaultSolver(Network network, int options, string name)
: base(network, options, name)
{
// get all soft constraints
_softConstraints = network.Constraints.Cast<Constraint>()
.Where(soft => soft.CType == ConstraintTypes.Soft).ToArray();
// get all values that have equal preferences
_valuesWhichHavePreferences = _softConstraints
.Where(soft => soft is Equals).Cast<Equals>()
.Select(s => ((IntDomain)s.Vars[1].Domain).Minimum())
.Distinct().
Union(_softConstraints
.Where(soft => soft is NotEquals).Cast<NotEquals>()
.Select(s => ((IntDomain)s.Vars[1].Domain).Minimum())
.Distinct()).ToArray();
GenerateOnlySameOrBetterWeightedSolutions = false;
Random = new Random();
}