• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cream.Network类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Cream.Network的典型用法代码示例。如果您正苦于以下问题:C# Network类的具体用法?C# Network怎么用?C# Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Network类属于Cream命名空间,在下文中一共展示了Network类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
            //------------------------------------------------------------------------------------------
        }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:35,代码来源:Program.cs


示例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;
 }
开发者ID:samplet,项目名称:HalfAndHalf,代码行数:10,代码来源:Constraint.cs


示例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;
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:7,代码来源:Relation.cs


示例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();
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:30,代码来源:EightQueensPuzzle.cs


示例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();
 }
开发者ID:samplet,项目名称:HalfAndHalf,代码行数:7,代码来源:Element.cs


示例6: Semantics

 public Semantics(Cell baseCell, Dictionary<string, Cell> cells,
     Network network, SpreadSheet spreadSheet)
 {
     _baseCell = baseCell;
       _cells = cells;
       _network = network;
       _spreadSheet = spreadSheet;
 }
开发者ID:samplet,项目名称:CreamCheese,代码行数:8,代码来源:Semantics.cs


示例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);
 }
开发者ID:samplet,项目名称:HalfAndHalf,代码行数:8,代码来源:Sequential.cs


示例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);
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:9,代码来源:Program.cs


示例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);
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:9,代码来源:Program.cs


示例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);
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:21,代码来源:Variable.cs


示例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();
        }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:56,代码来源:Program.cs


示例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();
     }
 }
开发者ID:samplet,项目名称:HalfAndHalf,代码行数:10,代码来源:Code.cs


示例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);
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:14,代码来源:Program.cs


示例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);
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:16,代码来源:Program.cs


示例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();
        }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:32,代码来源:DefaultSolver.cs


示例16: Solution

        /// <summary> Constructs a solution from the given network.</summary>
        /// <param name="network">the constraint network
        /// </param>
        public Solution(Network network)
        {
            _network = network;
            _objectiveDomain = null;
            if (network.Objective != null)
            {
                _objectiveDomain = network.Objective.Domain;
            }
            System.Collections.IList variables = network.Variables;
            _bindings = new Domain[variables.Count];
            System.Collections.IEnumerator vs = variables.GetEnumerator();
            while (vs.MoveNext())
            {
                var v = (Variable) vs.Current;
                _bindings[v.Index] = v.Domain;
            }
            // Do th efollowing for Soft constraints only
            //SwapValuesToPreferences();

            _code = new Code(network);
        }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:24,代码来源:Solution.cs


示例17: LocalSearch

 /// <summary> Constructs a random-walk solver for the given network, option, and name.</summary>
 /// <param name="network">the constraint network
 /// </param>
 /// <param name="option">the option 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 LocalSearch(Network network, int option, String name)
     : base(network, option, name)
 {
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:11,代码来源:LocalSearch.cs


示例18: IntArith

 private IntArith(Network net, int a, Variable[] v, ConstraintTypes cType, int weight)
     : base(net, cType, weight)
 {
     _arith = a;
     _v = v;
 }
开发者ID:kikoanis,项目名称:CSharpCream,代码行数:6,代码来源:IntArith.cs



注:本文中的Cream.Network类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cream.Variable类代码示例发布时间:2022-05-24
下一篇:
C# ParseTree.Expression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap