dotnet: Rework Xunit Tests
This commit is contained in:
@@ -39,10 +39,10 @@ test_dotnet: dotnet
|
||||
else
|
||||
dotnet: \
|
||||
ortoolslibs \
|
||||
csharp_dotnet \
|
||||
fsharp_dotnet
|
||||
dotnet_csharp \
|
||||
dotnet_fsharp
|
||||
|
||||
test_dotnet: test_dotnet_examples test_donet_samples
|
||||
test_dotnet: test_donet_samples test_dotnet_examples
|
||||
BUILT_LANGUAGES +=, dotnet \(netstandard2.0\)
|
||||
endif
|
||||
|
||||
@@ -71,14 +71,19 @@ 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 := runtime.$(RUNTIME_IDENTIFIER).$(OR_TOOLS_ASSEMBLY_NAME)
|
||||
OR_TOOLS_FSHARP_ASSEMBLY_NAME := $(OR_TOOLS_ASSEMBLY_NAME).FSharp
|
||||
OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME := $(OR_TOOLS_ASSEMBLY_NAME).FSharp.Tests
|
||||
DOTNET_ORTOOLS_NUPKG := $(PACKAGE_DIR)/$(OR_TOOLS_ASSEMBLY_NAME).$(OR_TOOLS_VERSION).nupkg
|
||||
DOTNET_ORTOOLS_NATIVE_NUPKG := $(PACKAGE_DIR)/$(OR_TOOLS_NATIVE_ASSEMBLY_NAME).$(OR_TOOLS_VERSION).nupkg
|
||||
DOTNET_ORTOOLS_FSHARP_NUPKG := $(PACKAGE_DIR)/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME).$(OR_TOOLS_VERSION).nupkg
|
||||
|
||||
.PHONY: csharp_dotnet # Build C# OR-Tools
|
||||
csharp_dotnet: $(DOTNET_ORTOOLS_NUPKG)
|
||||
######################
|
||||
## RUNTIME CSHARP ##
|
||||
######################
|
||||
.PHONY: dotnet_runtime # Build C# runtime OR-Tools
|
||||
dotnet_runtime: $(DOTNET_ORTOOLS_NATIVE_NUPKG)
|
||||
|
||||
# Protobufs generated code
|
||||
$(GEN_DIR)/ortools/constraint_solver/SearchLimit.pb.cs: \
|
||||
@@ -321,6 +326,12 @@ $(DOTNET_ORTOOLS_NATIVE_NUPKG): \
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_NATIVE_ASSEMBLY_NAME)$S$(OR_TOOLS_NATIVE_ASSEMBLY_NAME).csproj
|
||||
"$(DOTNET_BIN)" pack ortools$Sdotnet$S$(OR_TOOLS_NATIVE_ASSEMBLY_NAME)$S$(OR_TOOLS_NATIVE_ASSEMBLY_NAME).csproj
|
||||
|
||||
##############
|
||||
## CSHARP ##
|
||||
##############
|
||||
.PHONY: dotnet_csharp # Build C# OR-Tools
|
||||
dotnet_csharp: $(DOTNET_ORTOOLS_NUPKG)
|
||||
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_ASSEMBLY_NAME)/$(OR_TOOLS_ASSEMBLY_NAME).csproj: \
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_ASSEMBLY_NAME)/$(OR_TOOLS_ASSEMBLY_NAME).csproj.in
|
||||
$(SED) -e "s/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/" \
|
||||
@@ -338,14 +349,26 @@ $(DOTNET_ORTOOLS_NUPKG): \
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_ASSEMBLY_NAME)/$(OR_TOOLS_ASSEMBLY_NAME).csproj \
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_ASSEMBLY_NAME)/runtime.json \
|
||||
| $(PACKAGE_DIR)
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)$S$(OR_TOOLS_ASSEMBLY_NAME).csproj
|
||||
"$(DOTNET_BIN)" pack ortools$Sdotnet$S$(OR_TOOLS_ASSEMBLY_NAME)$S$(OR_TOOLS_ASSEMBLY_NAME).csproj
|
||||
"$(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
|
||||
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 ##
|
||||
##############
|
||||
.PHONY: fsharp_dotnet # Build F# OR-Tools
|
||||
fsharp_dotnet: $(DOTNET_ORTOOLS_FSHARP_NUPKG)
|
||||
.PHONY: dotnet_fsharp # Build F# OR-Tools
|
||||
dotnet_fsharp: $(DOTNET_ORTOOLS_FSHARP_NUPKG)
|
||||
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME).fsproj: \
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME).fsproj.in
|
||||
@@ -357,8 +380,20 @@ $(DOTNET_ORTOOLS_FSHARP_NUPKG): \
|
||||
$(DOTNET_ORTOOLS_NUPKG) \
|
||||
$(SRC_DIR)/ortools/dotnet/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)/$(OR_TOOLS_FSHARP_ASSEMBLY_NAME).fsproj \
|
||||
| $(PACKAGE_DIR)
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME).fsproj
|
||||
"$(DOTNET_BIN)" pack ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME).fsproj
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)
|
||||
"$(DOTNET_BIN)" pack ortools$Sdotnet$S$(OR_TOOLS_FSHARP_ASSEMBLY_NAME)
|
||||
|
||||
ortools/dotnet/$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)/$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME).fsproj: \
|
||||
ortools/dotnet/$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)/$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME).fsproj.in
|
||||
$(SED) -e "s/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/" \
|
||||
ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME).fsproj.in \
|
||||
> ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME).fsproj
|
||||
|
||||
.PHONY: test_dotnet_fsharp
|
||||
test_dotnet_fsharp: $(DOTNET_ORTOOLS_FSHARP_NUPKG) \
|
||||
ortools/dotnet/$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)/$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME).fsproj
|
||||
"$(DOTNET_BIN)" build ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)
|
||||
"$(DOTNET_BIN)" test ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)
|
||||
|
||||
#####################
|
||||
## .NET Examples ##
|
||||
@@ -375,9 +410,9 @@ EX_NAME = $(basename $(notdir $(EX)))
|
||||
cdotnet: $(TEMP_DOTNET_DIR)/$(EX_NAME)$D
|
||||
|
||||
.PHONY: rdotnet
|
||||
rdotnet: $(BIN_DIR)/$(EX_NAME)$D
|
||||
rdotnet: $(TEMP_DOTNET_DIR)/$(EX_NAME)$D
|
||||
@echo running $<
|
||||
"$(DOTNET_BIN)" $(BIN_DIR)$S$(EX_NAME)$D
|
||||
"$(DOTNET_BIN)" $(TEMP_DOTNET_DIR)$S$(EX_NAME)$D
|
||||
endif # ifeq ($(EX),)
|
||||
|
||||
$(TEMP_DOTNET_DIR)/%$D: \
|
||||
@@ -422,9 +457,15 @@ clean_dotnet:
|
||||
-$(DELREC) 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
|
||||
-$(DELREC) 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
|
||||
-$(DELREC) 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
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME).fsproj
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)$Sbin
|
||||
-$(DELREC) ortools$Sdotnet$S$(OR_TOOLS_FSHARP_TESTS_ASSEMBLY_NAME)$Sobj
|
||||
-$(DELREC) $(PACKAGE_DIR)
|
||||
-$(DEL) $(GEN_PATH)$Sortools$Salgorithms$S*.cs
|
||||
-$(DEL) $(GEN_PATH)$Sortools$Salgorithms$S*csharp_wrap*
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AssemblyName>Google.OrTools.FSharp.Tests</AssemblyName>
|
||||
<RootNamespace>Google.OrTools.FSharp.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<RestoreSources>../../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
@@ -17,13 +18,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||
<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>
|
||||
<ProjectReference Include="..\OrTools.FSharp\OrTools.FSharp.fsproj"/>
|
||||
<ProjectReference Include="..\OrTools\OrTools.csproj"/>
|
||||
<PackageReference Include="Google.OrTools" Version="@PROJECT_VERSION@" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,10 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||
<AssemblyName>Google.OrTools.Tests</AssemblyName>
|
||||
<RootNamespace>Google.OrTools.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<RestoreSources>../../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
@@ -12,12 +13,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||
<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>
|
||||
<ProjectReference Include="..\OrTools\OrTools.csproj"/>
|
||||
<PackageReference Include="Google.OrTools" Version="@PROJECT_VERSION@" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
189
ortools/dotnet/Google.OrTools.Tests/LinearProgramming.cs
Normal file
189
ortools/dotnet/Google.OrTools.Tests/LinearProgramming.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
using Google.OrTools.LinearSolver;
|
||||
|
||||
namespace Google.OrTools.Tests {
|
||||
public class LinearProgramming {
|
||||
[Fact]
|
||||
public void TestVarOperator() {
|
||||
Solver solver = new Solver("TestVarOperator", Solver.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(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(1.0, ct2.Ub());
|
||||
Assert.Equal(1.0, ct3.Lb());
|
||||
Assert.Equal(1.0, ct3.Ub());
|
||||
Assert.Equal(ct4.Lb(), double.NegativeInfinity);
|
||||
Assert.Equal(1.0, ct4.Ub());
|
||||
Assert.Equal(1.0, ct5.Lb());
|
||||
Assert.Equal(ct5.Ub(), double.PositiveInfinity);
|
||||
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);
|
||||
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);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(y));
|
||||
|
||||
Constraint ct2 = solver.Add(x + x == 1);
|
||||
Assert.Equal(2.0, ct2.GetCoefficient(x));
|
||||
|
||||
Constraint ct3 = solver.Add(x + (y + x) == 1);
|
||||
Assert.Equal(2.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct3.GetCoefficient(y));
|
||||
|
||||
Constraint ct4 = solver.Add(x + (y + x + 3) == 1);
|
||||
Assert.Equal(2.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(-2.0, ct4.Lb());
|
||||
Assert.Equal(-2.0, ct4.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVarMultiplication() {
|
||||
Solver solver = new Solver("TestVarMultiplication", Solver.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);
|
||||
Assert.Equal(3.0, ct1.GetCoefficient(x));
|
||||
|
||||
Constraint ct2 = solver.Add(x * 3 == 1);
|
||||
Assert.Equal(3.0, ct2.GetCoefficient(x));
|
||||
|
||||
Constraint ct3 = solver.Add(x + (2 * y + 3 * x) == 1);
|
||||
Assert.Equal(4.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(2.0, ct3.GetCoefficient(y));
|
||||
|
||||
Constraint ct4 = solver.Add(x + 5 * (y + x + 3) == 1);
|
||||
Assert.Equal(6.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(5.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(-14.0, ct4.Lb());
|
||||
Assert.Equal(-14.0, ct4.Ub());
|
||||
|
||||
Constraint ct5 = solver.Add(x + (2 * y + x + 3) * 3 == 1);
|
||||
Assert.Equal(4.0, ct5.GetCoefficient(x));
|
||||
Assert.Equal(6.0, ct5.GetCoefficient(y));
|
||||
Assert.Equal(-8.0, ct5.Lb());
|
||||
Assert.Equal(-8.0, ct5.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBinaryOperations() {
|
||||
Solver solver = new Solver("TestBinaryOperations", Solver.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);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
Assert.Equal(-1.0, ct1.GetCoefficient(y));
|
||||
|
||||
Constraint ct2 = solver.Add(x == 3 * y + 5);
|
||||
Assert.Equal(1.0, ct2.GetCoefficient(x));
|
||||
Assert.Equal(-3.0, ct2.GetCoefficient(y));
|
||||
Assert.Equal(5.0, ct2.Lb());
|
||||
Assert.Equal(5.0, ct2.Ub());
|
||||
|
||||
Constraint ct3 = solver.Add(2 * x - 9 == y);
|
||||
Assert.Equal(2.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(-1.0, ct3.GetCoefficient(y));
|
||||
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");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInequalities() {
|
||||
Solver solver = new Solver("TestInequalities", Solver.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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
Assert.Equal(8.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(6.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(double.NegativeInfinity, ct4.Lb());
|
||||
Assert.Equal(2.0, ct4.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSumArray() {
|
||||
Solver solver = new Solver("TestSumArray", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
|
||||
Variable[] x = solver.MakeBoolVarArray(10, "x");
|
||||
Constraint ct1 = solver.Add(x.Sum() == 3);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x[0]));
|
||||
|
||||
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 };
|
||||
Constraint ct3 = solver.Add(array.Sum() == 1);
|
||||
Assert.Equal(3.0, ct3.GetCoefficient(x[0]));
|
||||
Assert.Equal(-8.0, ct3.Lb());
|
||||
Assert.Equal(-8.0, ct3.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestObjective() {
|
||||
|
||||
Solver solver = new Solver("TestObjective", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
|
||||
solver.Maximize(x);
|
||||
Assert.Equal(0.0, solver.Objective().Offset());
|
||||
Assert.Equal(1.0, solver.Objective().GetCoefficient(x));
|
||||
Assert.True(solver.Objective().Maximization());
|
||||
|
||||
solver.Minimize(-x - 2 * y + 3);
|
||||
Assert.Equal(3.0, solver.Objective().Offset());
|
||||
Assert.Equal(-1.0, solver.Objective().GetCoefficient(x));
|
||||
Assert.Equal(-2.0, solver.Objective().GetCoefficient(y));
|
||||
Assert.True(solver.Objective().Minimization());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,34 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrTools", "OrTools\OrTools.csproj", "{AFA3F878-FB56-4314-B31E-3DA5583B548B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrTools.Tests", "OrTools.Tests\OrTools.Tests.csproj", "{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}"
|
||||
EndProject
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OrTools.FSharp", "OrTools.FSharp\OrTools.FSharp.fsproj", "{113A3FA7-F58E-4392-B6E9-5750813BE5D3}"
|
||||
EndProject
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OrTools.FSharp.Tests", "OrTools.FSharp.Tests\OrTools.FSharp.Tests.fsproj", "{06BDA79F-5C92-46A4-85DC-C0F5730CA495}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Debug|x64.Build.0 = Debug|x64
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Debug|x86.Build.0 = Debug|x86
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Release|x64.ActiveCfg = Release|x64
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Release|x64.Build.0 = Release|x64
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Release|x86.ActiveCfg = Release|x86
|
||||
{AFA3F878-FB56-4314-B31E-3DA5583B548B}.Release|x86.Build.0 = Release|x86
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Debug|x64.Build.0 = Debug|x64
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Debug|x86.Build.0 = Debug|x86
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Release|x64.ActiveCfg = Release|x64
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Release|x64.Build.0 = Release|x64
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Release|x86.ActiveCfg = Release|x86
|
||||
{CB6482EF-BFD1-4512-A24C-3AF3C8C70D3D}.Release|x86.Build.0 = Release|x86
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Debug|x64.Build.0 = Debug|x64
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Debug|x86.Build.0 = Debug|x86
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Release|x64.ActiveCfg = Release|x64
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Release|x64.Build.0 = Release|x64
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Release|x86.ActiveCfg = Release|x86
|
||||
{113A3FA7-F58E-4392-B6E9-5750813BE5D3}.Release|x86.Build.0 = Release|x86
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Debug|x64.Build.0 = Debug|x64
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Debug|x86.Build.0 = Debug|x86
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Release|x64.ActiveCfg = Release|x64
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Release|x64.Build.0 = Release|x64
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Release|x86.ActiveCfg = Release|x86
|
||||
{06BDA79F-5C92-46A4-85DC-C0F5730CA495}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "runtime.linux-x64.Google.OrTools", "runtime.linux-x64.Google.OrTools\runtime.linux-x64.Google.OrTools.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
using Google.OrTools.LinearSolver;
|
||||
|
||||
namespace Google.OrTools.Tests
|
||||
{
|
||||
public class LinearProgramming
|
||||
{
|
||||
[Fact]
|
||||
public void TestVarOperator()
|
||||
{
|
||||
Solver solver = new Solver("TestVarOperator", Solver.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(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(1.0, ct2.Ub());
|
||||
Assert.Equal(1.0, ct3.Lb());
|
||||
Assert.Equal(1.0, ct3.Ub());
|
||||
Assert.Equal(ct4.Lb(), double.NegativeInfinity);
|
||||
Assert.Equal(1.0, ct4.Ub());
|
||||
Assert.Equal(1.0, ct5.Lb());
|
||||
Assert.Equal(ct5.Ub(), double.PositiveInfinity);
|
||||
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);
|
||||
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);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(y));
|
||||
|
||||
Constraint ct2 = solver.Add(x + x == 1);
|
||||
Assert.Equal(2.0, ct2.GetCoefficient(x));
|
||||
|
||||
Constraint ct3 = solver.Add(x + (y + x) == 1);
|
||||
Assert.Equal(2.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct3.GetCoefficient(y));
|
||||
|
||||
Constraint ct4 = solver.Add(x + (y + x + 3) == 1);
|
||||
Assert.Equal(2.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(1.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(-2.0, ct4.Lb());
|
||||
Assert.Equal(-2.0, ct4.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVarMultiplication()
|
||||
{
|
||||
|
||||
Solver solver = new Solver("TestVarMultiplication", Solver.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);
|
||||
Assert.Equal(3.0, ct1.GetCoefficient(x));
|
||||
|
||||
Constraint ct2 = solver.Add(x * 3 == 1);
|
||||
Assert.Equal(3.0, ct2.GetCoefficient(x));
|
||||
|
||||
Constraint ct3 = solver.Add(x + (2 * y + 3 * x) == 1);
|
||||
Assert.Equal(4.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(2.0, ct3.GetCoefficient(y));
|
||||
|
||||
Constraint ct4 = solver.Add(x + 5 * (y + x + 3) == 1);
|
||||
Assert.Equal(6.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(5.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(-14.0, ct4.Lb());
|
||||
Assert.Equal(-14.0, ct4.Ub());
|
||||
|
||||
Constraint ct5 = solver.Add(x + (2 * y + x + 3) * 3 == 1);
|
||||
Assert.Equal(4.0, ct5.GetCoefficient(x));
|
||||
Assert.Equal(6.0, ct5.GetCoefficient(y));
|
||||
Assert.Equal(-8.0, ct5.Lb());
|
||||
Assert.Equal(-8.0, ct5.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBinaryOperations()
|
||||
{
|
||||
Solver solver = new Solver("TestBinaryOperations", Solver.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);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x));
|
||||
Assert.Equal(-1.0, ct1.GetCoefficient(y));
|
||||
|
||||
Constraint ct2 = solver.Add(x == 3 * y + 5);
|
||||
Assert.Equal(1.0, ct2.GetCoefficient(x));
|
||||
Assert.Equal(-3.0, ct2.GetCoefficient(y));
|
||||
Assert.Equal(5.0, ct2.Lb());
|
||||
Assert.Equal(5.0, ct2.Ub());
|
||||
|
||||
Constraint ct3 = solver.Add(2 * x - 9 == y);
|
||||
Assert.Equal(2.0, ct3.GetCoefficient(x));
|
||||
Assert.Equal(-1.0, ct3.GetCoefficient(y));
|
||||
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");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInequalities()
|
||||
{
|
||||
Solver solver = new Solver("TestInequalities", Solver.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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
Assert.Equal(8.0, ct4.GetCoefficient(x));
|
||||
Assert.Equal(6.0, ct4.GetCoefficient(y));
|
||||
Assert.Equal(double.NegativeInfinity, ct4.Lb());
|
||||
Assert.Equal(2.0, ct4.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSumArray()
|
||||
{
|
||||
Solver solver = new Solver("TestSumArray", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
|
||||
Variable[] x = solver.MakeBoolVarArray(10, "x");
|
||||
Constraint ct1 = solver.Add(x.Sum() == 3);
|
||||
Assert.Equal(1.0, ct1.GetCoefficient(x[0]));
|
||||
|
||||
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 };
|
||||
Constraint ct3 = solver.Add(array.Sum() == 1);
|
||||
Assert.Equal(3.0, ct3.GetCoefficient(x[0]));
|
||||
Assert.Equal(-8.0, ct3.Lb());
|
||||
Assert.Equal(-8.0, ct3.Ub());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestObjective()
|
||||
{
|
||||
|
||||
Solver solver = new Solver("TestObjective", Solver.CLP_LINEAR_PROGRAMMING);
|
||||
|
||||
Variable x = solver.MakeNumVar(0.0, 100.0, "x");
|
||||
Variable y = solver.MakeNumVar(0.0, 100.0, "y");
|
||||
|
||||
solver.Maximize(x);
|
||||
Assert.Equal(0.0, solver.Objective().Offset());
|
||||
Assert.Equal(1.0, solver.Objective().GetCoefficient(x));
|
||||
Assert.True(solver.Objective().Maximization());
|
||||
|
||||
solver.Minimize(-x - 2 * y + 3);
|
||||
Assert.Equal(3.0, solver.Objective().Offset());
|
||||
Assert.Equal(-1.0, solver.Objective().GetCoefficient(x));
|
||||
Assert.Equal(-2.0, solver.Objective().GetCoefficient(y));
|
||||
Assert.True(solver.Objective().Minimization());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user