.Net: Add LinearSolverTests.cs
- remove duplicate testlp.cs and Google.OrTools.Tests
This commit is contained in:
@@ -1,46 +1,61 @@
|
||||
using System;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
using Google.OrTools.LinearSolver;
|
||||
|
||||
namespace Google.OrTools.Tests {
|
||||
public class LinearProgramming {
|
||||
public class LinearSolverTest {
|
||||
[Fact]
|
||||
public void TestVarOperator() {
|
||||
Solver solver = new Solver("TestVarOperator", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
public void VarOperator() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Constraint ct1 = solver.Add(x >= 1);
|
||||
Constraint ct2 = solver.Add(x <= 1);
|
||||
Constraint ct3 = solver.Add(x == 1);
|
||||
Constraint ct4 = solver.Add(1 >= x);
|
||||
Constraint ct5 = solver.Add(1 <= x);
|
||||
Constraint ct6 = solver.Add(1 == x);
|
||||
Assert.Equal(0.0, x.Lb());
|
||||
Assert.Equal(100.0, x.Ub());
|
||||
|
||||
Constraint ct1 = solver.Add(x >= 1);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct2.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct5.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct6.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct1.Lb());
|
||||
Assert.Equal(ct1.Ub(), double.PositiveInfinity);
|
||||
Assert.Equal(ct2.Lb(), double.NegativeInfinity);
|
||||
Assert.Equal(double.PositiveInfinity, ct1.Ub());
|
||||
|
||||
Constraint ct2 = solver.Add(x <= 1);
|
||||
Assert.Equal(1.0, ct2.GetCoefficient(x));
|
||||
Assert.Equal(double.NegativeInfinity, ct2.Lb());
|
||||
Assert.Equal(1.0, ct2.Ub());
|
||||
|
||||
Constraint ct3 = solver.Add(x == 1);
|
||||
Assert.Equal(1.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct3.Lb());
|
||||
Assert.Equal(1.0, ct3.Ub());
|
||||
Assert.Equal(ct4.Lb(), double.NegativeInfinity);
|
||||
|
||||
Constraint ct4 = solver.Add(1 >= x);
|
||||
Assert.Equal(1.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(double.NegativeInfinity, ct4.Lb());
|
||||
Assert.Equal(1.0, ct4.Ub());
|
||||
|
||||
Constraint ct5 = solver.Add(1 <= x);
|
||||
Assert.Equal(1.0, ct5.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct5.Lb());
|
||||
Assert.Equal(ct5.Ub(), double.PositiveInfinity);
|
||||
Assert.Equal(double.PositiveInfinity, ct5.Ub());
|
||||
|
||||
Constraint ct6 = solver.Add(1 == x);
|
||||
Assert.Equal(1.0, ct6.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct6.Lb());
|
||||
Assert.Equal(1.0, ct6.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVarAddition() {
|
||||
Solver solver = new Solver("TestVarAddition", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
public void VarAddition() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Assert.Equal(0.0, x.Lb());
|
||||
Assert.Equal(100.0, x.Ub());
|
||||
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Assert.Equal(0.0, y.Lb());
|
||||
Assert.Equal(100.0, y.Ub());
|
||||
|
||||
Constraint ct1 = solver.Add(x + y == 1);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
@@ -61,10 +76,17 @@ namespace Google.OrTools.Tests {
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVarMultiplication() {
|
||||
Solver solver = new Solver("TestVarMultiplication", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
public void VarMultiplication() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Assert.Equal(0.0, x.Lb());
|
||||
Assert.Equal(100.0, x.Ub());
|
||||
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Assert.Equal(0.0, y.Lb());
|
||||
Assert.Equal(100.0, y.Ub());
|
||||
|
||||
Constraint ct1 = solver.Add(3 * x == 1);
|
||||
Assert.Equal(3.0, ct1.GetCoefficient(x));
|
||||
@@ -90,10 +112,17 @@ namespace Google.OrTools.Tests {
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBinaryOperations() {
|
||||
Solver solver = new Solver("TestBinaryOperations", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
public void BinaryOperator() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Assert.Equal(0.0, x.Lb());
|
||||
Assert.Equal(100.0, x.Ub());
|
||||
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Assert.Equal(0.0, y.Lb());
|
||||
Assert.Equal(100.0, y.Ub());
|
||||
|
||||
Constraint ct1 = solver.Add(x == y);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
@@ -111,37 +140,44 @@ namespace Google.OrTools.Tests {
|
||||
Assert.Equal(9.0, ct3.Lb());
|
||||
Assert.Equal(9.0, ct3.Ub());
|
||||
|
||||
Assert.True(x == x, "test11");
|
||||
Assert.True(!(x == y), "test12");
|
||||
Assert.True(!(x != x), "test13");
|
||||
Assert.True((x != y), "test14");
|
||||
Assert.True(x == x);
|
||||
Assert.True(!(x != x));
|
||||
Assert.True((x != y));
|
||||
Assert.True(!(x == y));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInequalities() {
|
||||
Solver solver = new Solver("TestInequalities", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
public void Inequalities() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Assert.Equal(0.0, x.Lb());
|
||||
Assert.Equal(100.0, x.Ub());
|
||||
|
||||
Constraint ct1 = solver.Add(2 * (x + 3) + 5 * (y + x - 1) >= 3);
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Assert.Equal(0.0, y.Lb());
|
||||
Assert.Equal(100.0, y.Ub());
|
||||
|
||||
Constraint ct1 = solver.Add(2 * (x + 3) + 5 * (y + x -1) >= 3);
|
||||
Assert.Equal(7.0, ct1.GetCoefficient(x));
|
||||
Assert.Equal(5.0, ct1.GetCoefficient(y));
|
||||
Assert.Equal(2.0, ct1.Lb());
|
||||
Assert.Equal(double.PositiveInfinity, ct1.Ub());
|
||||
|
||||
Constraint ct2 = solver.Add(2 * (x + 3) + 5 * (y + x - 1) <= 3);
|
||||
Constraint ct2 = solver.Add(2 * (x + 3) + 5 * (y + x -1) <= 3);
|
||||
Assert.Equal(7.0, ct2.GetCoefficient(x));
|
||||
Assert.Equal(5.0, ct2.GetCoefficient(y));
|
||||
Assert.Equal(double.NegativeInfinity, ct2.Lb());
|
||||
Assert.Equal(2.0, ct2.Ub());
|
||||
|
||||
Constraint ct3 = solver.Add(2 * (x + 3) + 5 * (y + x - 1) >= 3 - x - y);
|
||||
Constraint ct3 = solver.Add(2 * (x + 3) + 5 * (y + x -1) >= 3 - x - y);
|
||||
Assert.Equal(8.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(6.0, ct3.GetCoefficient(y));
|
||||
Assert.Equal(2.0, ct3.Lb());
|
||||
Assert.Equal(double.PositiveInfinity, ct3.Ub());
|
||||
|
||||
Constraint ct4 = solver.Add(2 * (x + 3) + 5 * (y + x - 1) <= -x - y + 3);
|
||||
Constraint ct4 = solver.Add(2 * (x + 3) + 5 * (y + x -1) <= -x - y + 3);
|
||||
Assert.Equal(8.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(6.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(double.NegativeInfinity, ct4.Lb());
|
||||
@@ -149,8 +185,10 @@ namespace Google.OrTools.Tests {
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSumArray() {
|
||||
Solver solver = new Solver("TestSumArray", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
public void SumArray() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
|
||||
Variable[] x = solver.MakeBoolVarArray(10, "x");
|
||||
Constraint ct1 = solver.Add(x.Sum() == 3);
|
||||
@@ -159,7 +197,7 @@ namespace Google.OrTools.Tests {
|
||||
Constraint ct2 = solver.Add(-2 * x.Sum() == 3);
|
||||
Assert.Equal(-2.0, ct2.GetCoefficient(x[0]));
|
||||
|
||||
LinearExpr[] array = new LinearExpr[] { x[0] + 2.0, x[0] + 3, x[0] + 4 };
|
||||
LinearExpr[] array = new LinearExpr[] { x[0]+ 2.0, x[0] + 3, x[0] + 4 };
|
||||
Constraint ct3 = solver.Add(array.Sum() == 1);
|
||||
Assert.Equal(3.0, ct3.GetCoefficient(x[0]));
|
||||
Assert.Equal(-8.0, ct3.Lb());
|
||||
@@ -167,12 +205,17 @@ namespace Google.OrTools.Tests {
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestObjective() {
|
||||
|
||||
Solver solver = new Solver("TestObjective", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
|
||||
public void Objective() {
|
||||
Solver solver = new Solver(
|
||||
"Solver",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Assert.Equal(0.0, x.Lb());
|
||||
Assert.Equal(100.0, x.Ub());
|
||||
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Assert.Equal(0.0, y.Lb());
|
||||
Assert.Equal(100.0, y.Ub());
|
||||
|
||||
solver.Maximize(x);
|
||||
Assert.Equal(0.0, solver.Objective().Offset());
|
||||
@@ -186,4 +229,5 @@ namespace Google.OrTools.Tests {
|
||||
Assert.True(solver.Objective().Minimization());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Google.OrTools.Tests
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||
<AssemblyName>Google.OrTools.Tests</AssemblyName>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<EnableDefaultItems>false</EnableDefaultItems>
|
||||
<AssemblyName>Google.OrTools.LinearSolverTests</AssemblyName>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<RestoreSources>../../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
|
||||
<RestoreSources>../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
@@ -13,13 +15,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="LinearSolverTests.cs" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.OrTools" Version="@PROJECT_VERSION@" />
|
||||
<PackageReference Include="Google.OrTools" Version="7.0.6170-*" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -37,174 +37,6 @@ public class CsTestLp
|
||||
}
|
||||
}
|
||||
|
||||
static void TestVarOperator()
|
||||
{
|
||||
Console.WriteLine("Running TestVarOperator");
|
||||
Solver solver = new Solver("TestVarOperator",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Constraint ct1 = solver.Add(x >= 1);
|
||||
Constraint ct2 = solver.Add(x <= 1);
|
||||
Constraint ct3 = solver.Add(x == 1);
|
||||
Constraint ct4 = solver.Add(1 >= x);
|
||||
Constraint ct5 = solver.Add(1 <= x);
|
||||
Constraint ct6 = solver.Add(1 == x);
|
||||
CheckDoubleEq(ct1.GetCoefficient(x), 1.0, "test1");
|
||||
CheckDoubleEq(ct2.GetCoefficient(x), 1.0, "test2");
|
||||
CheckDoubleEq(ct3.GetCoefficient(x), 1.0, "test3");
|
||||
CheckDoubleEq(ct4.GetCoefficient(x), 1.0, "test4");
|
||||
CheckDoubleEq(ct5.GetCoefficient(x), 1.0, "test5");
|
||||
CheckDoubleEq(ct6.GetCoefficient(x), 1.0, "test6");
|
||||
CheckDoubleEq(ct1.Lb(), 1.0, "test7");
|
||||
CheckDoubleEq(ct1.Ub(), double.PositiveInfinity, "test8");
|
||||
CheckDoubleEq(ct2.Lb(), double.NegativeInfinity, "test9");
|
||||
CheckDoubleEq(ct2.Ub(), 1.0, "test10");
|
||||
CheckDoubleEq(ct3.Lb(), 1.0, "test11");
|
||||
CheckDoubleEq(ct3.Ub(), 1.0, "test12");
|
||||
CheckDoubleEq(ct4.Lb(), double.NegativeInfinity, "test13");
|
||||
CheckDoubleEq(ct4.Ub(), 1.0, "test14");
|
||||
CheckDoubleEq(ct5.Lb(), 1.0, "test15");
|
||||
CheckDoubleEq(ct5.Ub(), double.PositiveInfinity, "test16");
|
||||
CheckDoubleEq(ct6.Lb(), 1.0, "test17");
|
||||
CheckDoubleEq(ct6.Ub(), 1.0, "test18");
|
||||
}
|
||||
|
||||
static void TestVarAddition()
|
||||
{
|
||||
Console.WriteLine("Running TestVarAddition");
|
||||
Solver solver = new Solver("TestVarAddition",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Constraint ct1 = solver.Add(x + y == 1);
|
||||
CheckDoubleEq(ct1.GetCoefficient(x), 1.0, "test1");
|
||||
CheckDoubleEq(ct1.GetCoefficient(y), 1.0, "test2");
|
||||
Constraint ct2 = solver.Add(x + x == 1);
|
||||
CheckDoubleEq(ct2.GetCoefficient(x), 2.0, "test3");
|
||||
Constraint ct3 = solver.Add(x + (y + x) == 1);
|
||||
CheckDoubleEq(ct3.GetCoefficient(x), 2.0, "test4");
|
||||
CheckDoubleEq(ct3.GetCoefficient(y), 1.0, "test5");
|
||||
Constraint ct4 = solver.Add(x + (y + x + 3) == 1);
|
||||
CheckDoubleEq(ct4.GetCoefficient(x), 2.0, "test4");
|
||||
CheckDoubleEq(ct4.GetCoefficient(y), 1.0, "test5");
|
||||
CheckDoubleEq(ct4.Lb(), -2.0, "test6");
|
||||
CheckDoubleEq(ct4.Ub(), -2.0, "test7");
|
||||
}
|
||||
|
||||
static void TestVarMultiplication()
|
||||
{
|
||||
Console.WriteLine("Running TestVarMultiplication");
|
||||
Solver solver = new Solver("TestVarMultiplication",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Constraint ct1 = solver.Add(3 * x == 1);
|
||||
CheckDoubleEq(ct1.GetCoefficient(x), 3.0, "test1");
|
||||
Constraint ct2 = solver.Add(x * 3 == 1);
|
||||
CheckDoubleEq(ct2.GetCoefficient(x), 3.0, "test2");
|
||||
Constraint ct3 = solver.Add(x + (2 * y + 3 * x) == 1);
|
||||
CheckDoubleEq(ct3.GetCoefficient(x), 4.0, "test3");
|
||||
CheckDoubleEq(ct3.GetCoefficient(y), 2.0, "test4");
|
||||
Constraint ct4 = solver.Add(x + 5 * (y + x + 3) == 1);
|
||||
CheckDoubleEq(ct4.GetCoefficient(x), 6.0, "test5");
|
||||
CheckDoubleEq(ct4.GetCoefficient(y), 5.0, "test6");
|
||||
CheckDoubleEq(ct4.Lb(), -14.0, "test7");
|
||||
CheckDoubleEq(ct4.Ub(), -14.0, "test8");
|
||||
Constraint ct5 = solver.Add(x + (2 * y + x + 3) * 3 == 1);
|
||||
CheckDoubleEq(ct5.GetCoefficient(x), 4.0, "test9");
|
||||
CheckDoubleEq(ct5.GetCoefficient(y), 6.0, "test10");
|
||||
CheckDoubleEq(ct5.Lb(), -8.0, "test11");
|
||||
CheckDoubleEq(ct5.Ub(), -8.0, "test12");
|
||||
}
|
||||
|
||||
static void TestBinaryOperations()
|
||||
{
|
||||
Console.WriteLine("Running TestBinaryOperations");
|
||||
Solver solver = new Solver("TestBinaryOperations",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Constraint ct1 = solver.Add(x == y);
|
||||
CheckDoubleEq(ct1.GetCoefficient(x), 1.0, "test1");
|
||||
CheckDoubleEq(ct1.GetCoefficient(y), -1.0, "test2");
|
||||
Constraint ct2 = solver.Add(x == 3 * y + 5);
|
||||
CheckDoubleEq(ct2.GetCoefficient(x), 1.0, "test3");
|
||||
CheckDoubleEq(ct2.GetCoefficient(y), -3.0, "test4");
|
||||
CheckDoubleEq(ct2.Lb(), 5.0, "test5");
|
||||
CheckDoubleEq(ct2.Ub(), 5.0, "test6");
|
||||
Constraint ct3 = solver.Add(2 * x - 9 == y);
|
||||
CheckDoubleEq(ct3.GetCoefficient(x), 2.0, "test7");
|
||||
CheckDoubleEq(ct3.GetCoefficient(y), -1.0, "test8");
|
||||
CheckDoubleEq(ct3.Lb(), 9.0, "test9");
|
||||
CheckDoubleEq(ct3.Ub(), 9.0, "test10");
|
||||
Check(x == x, "test11");
|
||||
Check(!(x == y), "test12");
|
||||
Check(!(x != x), "test13");
|
||||
Check((x != y), "test14");
|
||||
}
|
||||
|
||||
static void TestInequalities()
|
||||
{
|
||||
Console.WriteLine("Running TestInequalities");
|
||||
Solver solver = new Solver("TestInequalities",
|
||||
Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
Constraint ct1 = solver.Add(2 * (x + 3) + 5 * (y + x -1) >= 3);
|
||||
CheckDoubleEq(ct1.GetCoefficient(x), 7.0, "test1");
|
||||
CheckDoubleEq(ct1.GetCoefficient(y), 5.0, "test2");
|
||||
CheckDoubleEq(ct1.Lb(), 2.0, "test3");
|
||||
CheckDoubleEq(ct1.Ub(), double.PositiveInfinity, "test4");
|
||||
Constraint ct2 = solver.Add(2 * (x + 3) + 5 * (y + x -1) <= 3);
|
||||
CheckDoubleEq(ct2.GetCoefficient(x), 7.0, "test5");
|
||||
CheckDoubleEq(ct2.GetCoefficient(y), 5.0, "test6");
|
||||
CheckDoubleEq(ct2.Lb(), double.NegativeInfinity, "test7");
|
||||
CheckDoubleEq(ct2.Ub(), 2.0, "test8");
|
||||
Constraint ct3 = solver.Add(2 * (x + 3) + 5 * (y + x -1) >= 3 - x - y);
|
||||
CheckDoubleEq(ct3.GetCoefficient(x), 8.0, "test9");
|
||||
CheckDoubleEq(ct3.GetCoefficient(y), 6.0, "test10");
|
||||
CheckDoubleEq(ct3.Lb(), 2.0, "test11");
|
||||
CheckDoubleEq(ct3.Ub(), double.PositiveInfinity, "test12");
|
||||
Constraint ct4 = solver.Add(2 * (x + 3) + 5 * (y + x -1) <= -x - y + 3);
|
||||
CheckDoubleEq(ct4.GetCoefficient(x), 8.0, "test13");
|
||||
CheckDoubleEq(ct4.GetCoefficient(y), 6.0, "test14");
|
||||
CheckDoubleEq(ct4.Lb(), double.NegativeInfinity, "test15");
|
||||
CheckDoubleEq(ct4.Ub(), 2.0, "test16");
|
||||
}
|
||||
|
||||
static void TestSumArray()
|
||||
{
|
||||
Console.WriteLine("Running TestSumArray");
|
||||
Solver solver = new Solver("TestSumArray", Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable[] x = solver.MakeBoolVarArray(10, "x");
|
||||
Constraint ct1 = solver.Add(x.Sum() == 3);
|
||||
CheckDoubleEq(ct1.GetCoefficient(x[0]), 1.0, "test1");
|
||||
Constraint ct2 = solver.Add(-2 * x.Sum() == 3);
|
||||
CheckDoubleEq(ct2.GetCoefficient(x[0]), -2.0, "test2");
|
||||
LinearExpr[] array = new LinearExpr[] { x[0]+ 2.0, x[0] + 3, x[0] + 4 };
|
||||
Constraint ct3 = solver.Add(array.Sum() == 1);
|
||||
CheckDoubleEq(ct3.GetCoefficient(x[0]), 3.0, "test3");
|
||||
CheckDoubleEq(ct3.Lb(), -8.0, "test4");
|
||||
CheckDoubleEq(ct3.Ub(), -8.0, "test5");
|
||||
}
|
||||
|
||||
static void TestObjective()
|
||||
{
|
||||
Console.WriteLine("Running TestObjective");
|
||||
Solver solver = new Solver("TestObjective", Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING);
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
solver.Maximize(x);
|
||||
CheckDoubleEq(0.0, solver.Objective().Offset(), "test1");
|
||||
CheckDoubleEq(1.0, solver.Objective().GetCoefficient(x), "test2");
|
||||
Check(solver.Objective().Maximization(), "test3");
|
||||
solver.Minimize(-x - 2 * y + 3);
|
||||
CheckDoubleEq(3.0, solver.Objective().Offset(), "test4");
|
||||
CheckDoubleEq(-1.0, solver.Objective().GetCoefficient(x), "test5");
|
||||
CheckDoubleEq(-2.0, solver.Objective().GetCoefficient(y), "test6");
|
||||
Check(solver.Objective().Minimization(), "test7");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
TestVarOperator();
|
||||
|
||||
@@ -68,7 +68,6 @@ endif
|
||||
DOTNET_ORTOOLS_SNK := $(BIN_DIR)/or-tools.snk
|
||||
DOTNET_ORTOOLS_SNK_PATH := $(subst /,$S,$(DOTNET_ORTOOLS_SNK))
|
||||
OR_TOOLS_ASSEMBLY_NAME := Google.OrTools
|
||||
OR_TOOLS_TESTS_ASSEMBLY_NAME := Google.OrTools.Tests
|
||||
OR_TOOLS_NATIVE_ASSEMBLY_NAME := $(OR_TOOLS_ASSEMBLY_NAME).runtime.$(RUNTIME_IDENTIFIER)
|
||||
OR_TOOLS_FSHARP_ASSEMBLY_NAME := $(OR_TOOLS_ASSEMBLY_NAME).FSharp
|
||||
OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME := $(OR_TOOLS_ASSEMBLY_NAME).FSharp.Tests
|
||||
@@ -365,18 +364,6 @@ $(DOTNET_ORTOOLS_NUPKG): \
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)
|
||||
"$(DOTNET_BIN)" pack ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)
|
||||
|
||||
ortools/dotnet/$(OR_TOOLS_TESTS_ASSEMBLY_NAME)/$(OR_TOOLS_TESTS_ASSEMBLY_NAME).csproj: \
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_TESTS_ASSEMBLY_NAME)/$(OR_TOOLS_TESTS_ASSEMBLY_NAME).csproj.in
|
||||
$(SED) -e "s/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/" \
|
||||
ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME).csproj.in \
|
||||
> ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME).csproj
|
||||
|
||||
.PHONY: test_dotnet_csharp # Run C# OrTools Tests
|
||||
test_dotnet_csharp: $(DOTNET_ORTOOLS_NUPKG) \
|
||||
ortools/dotnet/$(OR_TOOLS_TESTS_ASSEMBLY_NAME)/$(OR_TOOLS_TESTS_ASSEMBLY_NAME).csproj
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)
|
||||
"$(DOTNET_BIN)" test ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)
|
||||
|
||||
##############
|
||||
## FSHARP ##
|
||||
##############
|
||||
@@ -505,12 +492,12 @@ check_dotnet_pimpl: \
|
||||
|
||||
.PHONY: test_dotnet_tests # Build and Run all .Net Tests (located in examples/test)
|
||||
test_dotnet_tests:
|
||||
$(MAKE) run_test SOURCE=examples/tests/LinearSolverTests.cs
|
||||
$(MAKE) run_test SOURCE=examples/tests/ConstraintSolverTests.cs
|
||||
$(MAKE) run_test SOURCE=examples/tests/RoutingSolverTests.cs
|
||||
$(MAKE) run SOURCE=examples/tests/issue18.cs
|
||||
$(MAKE) run SOURCE=examples/tests/issue22.cs
|
||||
$(MAKE) run SOURCE=examples/tests/issue33.cs
|
||||
$(MAKE) run SOURCE=examples/tests/testlp.cs
|
||||
$(MAKE) run SOURCE=examples/tests/testsat.cs
|
||||
$(MAKE) run SOURCE=examples/tests/test_sat_model.cs
|
||||
|
||||
@@ -678,9 +665,6 @@ clean_dotnet:
|
||||
-$(DEL) ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)$Sruntime.json
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)$Sbin
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)$Sobj
|
||||
-$(DEL) ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)*.csproj
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)$Sbin
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_TESTS_ASSEMBLY_NAME)$Sobj
|
||||
-$(DEL) ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)*.fsproj
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)$Sbin
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)$Sobj
|
||||
@@ -757,7 +741,6 @@ detect_dotnet:
|
||||
@echo DOTNET_ORTOOLS_NATIVE_NUPKG = $(DOTNET_ORTOOLS_NATIVE_NUPKG)
|
||||
@echo OR_TOOLS_ASSEMBLY_NAME = $(OR_TOOLS_ASSEMBLY_NAME)
|
||||
@echo DOTNET_ORTOOLS_NUPKG = $(DOTNET_ORTOOLS_NUPKG)
|
||||
@echo OR_TOOLS_TESTS_ASSEMBLY_NAME = $(OR_TOOLS_TESTS_ASSEMBLY_NAME)
|
||||
@echo OR_TOOLS_FSHARP_ASSEMBLY_NAME = $(OR_TOOLS_FSHARP_ASSEMBLY_NAME)
|
||||
@echo DOTNET_ORTOOLS_FSHARP_NUPKG = $(DOTNET_ORTOOLS_FSHARP_NUPKG)
|
||||
@echo OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME = $(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Google.OrTools.Tests
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user