Esempio n. 1
0
        public void SolveFromString()
        {
            string       model_str = @"
            { 
              ""variables"": [
                { ""name"": ""C"", ""domain"": [ ""1"", ""9"" ] },
                { ""name"": ""P"", ""domain"": [ ""0"", ""9"" ] },
                { ""name"": ""I"", ""domain"": [ ""1"", ""9"" ] },
                { ""name"": ""S"", ""domain"": [ ""0"", ""9"" ] },
                { ""name"": ""F"", ""domain"": [ ""1"", ""9"" ] },
                { ""name"": ""U"", ""domain"": [ ""0"", ""9"" ] },
                { ""name"": ""N"", ""domain"": [ ""0"", ""9"" ] },
                { ""name"": ""T"", ""domain"": [ ""1"", ""9"" ] },
                { ""name"": ""R"", ""domain"": [ ""0"", ""9"" ] },
                { ""name"": ""E"", ""domain"": [ ""0"", ""9"" ] }
              ],
              ""constraints"": [
                { ""allDiff"": { ""vars"": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } },
                { ""linear"": { ""vars"": [ 6, 5, 9, 4, 3, 7, 8, 2, 0, 1 ], ""coeffs"": [ ""1"", ""0"", ""-1"", ""100"", ""1"", ""-1000"", ""-100"", ""10"", ""10"", ""1"" ], ""domain"": [ ""0"", ""0"" ] } }
              ]
            }";
            CpModelProto model     = Google.Protobuf.JsonParser.Default.Parse <CpModelProto>(model_str);

            CpSolverResponse response = SatHelper.Solve(model);

            Console.WriteLine(response);
        }
Esempio n. 2
0
 public CpSolverStatus Solve(CpModel model)
 {
     if (string_parameters_ != null)
     {
         response_ = SatHelper.SolveWithStringParameters(model.Model, string_parameters_);
     }
     else
     {
         response_ = SatHelper.Solve(model.Model);
     }
     return(response_.Status);
 }
Esempio n. 3
0
 public CpSolverStatus SolveWithSolutionCallback(CpModel model,
                                                 SolutionCallback cb)
 {
     if (string_parameters_ != null)
     {
         response_ = SatHelper.SolveWithStringParametersAndSolutionCallback(
             model.Model, string_parameters_, cb);
     }
     else
     {
         response_ = SatHelper.Solve(model.Model);
     }
     return(response_.Status);
 }
Esempio n. 4
0
    static void TestSimpleLinearModel2()
    {
        CpModelProto model = new CpModelProto();

        model.Variables.Add(NewIntegerVariable(-10, 10));
        model.Variables.Add(NewIntegerVariable(-10, 10));
        model.Constraints.Add(NewLinear2(0, 1, 1, 1, -1000000, 100000));
        model.Objective = NewMaximize2(0, 1, 1, -2);

        CpSolverResponse response = SatHelper.Solve(model);

        Console.WriteLine("model = " + model.ToString());
        Console.WriteLine("response = " + response.ToString());
    }
Esempio n. 5
0
        public void SimpleLinearModelProto2()
        {
            CpModelProto model = new CpModelProto();
            model.Variables.Add(NewIntegerVariable(-10, 10));
            model.Variables.Add(NewIntegerVariable(-10, 10));
            model.Constraints.Add(NewLinear2(0, 1 , 1, 1, -1000000, 100000));
            model.Objective = NewMaximize2(0, 1, 1, -2);
            //Console.WriteLine("model = " + model.ToString());

            CpSolverResponse response = SatHelper.Solve(model);
            Assert.Equal(CpSolverStatus.Optimal, response.Status);
            Assert.Equal(30, response.ObjectiveValue);
            Assert.Equal(new long[] {10, -10}, response.Solution);
            //Console.WriteLine("response = " + response.ToString());
        }