Files
ortools-clone/examples/tests/issue18.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2025-01-10 11:35:44 +01:00
// Copyright 2010-2025 Google LLC
2013-01-15 13:31:41 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2013-01-15 13:31:41 +00:00
using System;
using System.Collections.Generic;
using Google.OrTools.ConstraintSolver;
2022-09-28 18:21:45 +02:00
public class Issue18
2020-11-03 10:04:19 +01:00
{
2022-09-28 18:21:45 +02:00
public static void NewSearchTest()
2020-11-03 10:04:19 +01:00
{
Solver solver = new Google.OrTools.ConstraintSolver.Solver("p");
// creating dummy variables
List<IntVar> vars = new List<IntVar>();
for (int i = 0; i < 100000; i++)
{
vars.Add(solver.MakeIntVar(0, 1));
}
IntExpr globalSum = solver.MakeSum(vars.ToArray());
DecisionBuilder db = solver.MakePhase(vars.ToArray(), Google.OrTools.ConstraintSolver.Solver.INT_VAR_SIMPLE,
Google.OrTools.ConstraintSolver.Solver.INT_VALUE_SIMPLE);
solver.NewSearch(db, new OptimizeVar(solver, true, globalSum.Var(), 100));
// force Garbage Collector
GC.Collect();
GC.WaitForPendingFinalizers();
// Try to read all solutions
int count = 0;
while (solver.NextSolution())
2020-11-03 10:04:19 +01:00
{
count++;
2023-05-30 17:56:49 +02:00
Console.WriteLine("solution " + count + " found");
// Console.WriteLine("solution " + globalSum.Var().Value());
2023-05-30 17:56:49 +02:00
if (count > 10)
{
2023-07-13 14:29:12 +02:00
break;
2023-05-30 17:56:49 +02:00
}
2020-11-03 10:04:19 +01:00
}
Console.WriteLine("Solutions: " + count);
2013-01-15 13:31:41 +00:00
}
2022-09-28 18:21:45 +02:00
static void Main()
{
NewSearchTest();
}
}