diff --git a/examples/tests/RoutingSolverTests.cs b/examples/tests/RoutingSolverTests.cs new file mode 100644 index 0000000000..23fcc56d86 --- /dev/null +++ b/examples/tests/RoutingSolverTests.cs @@ -0,0 +1,40 @@ +using System; +using Xunit; +using Google.OrTools.ConstraintSolver; + +namespace Google.OrTools.Tests { + public class RoutingSolverTest { + [Theory] + [InlineData(false)] + [InlineData(true)] + public void SimpleLambdaCallback(bool callGC) { + // Create Routing Index Manager + RoutingIndexManager manager = new RoutingIndexManager( + 5/*locations*/, 1/*vehicle*/, 0/*depot*/); + // Create Routing Model. + RoutingModel routing = new RoutingModel(manager); + // Create a distance callback. + int transitCallbackIndex = routing.RegisterTransitCallback( + (long fromIndex, long toIndex) => { + // Convert from routing variable Index to distance matrix NodeIndex. + var fromNode = manager.IndexToNode(fromIndex); + var toNode = manager.IndexToNode(toIndex); + return Math.Abs(toNode - fromNode); + }); + // Define cost of each arc. + routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex); + if (callGC) { + GC.Collect(); + } + // Setting first solution heuristic. + RoutingSearchParameters searchParameters = + operations_research_constraint_solver.DefaultRoutingSearchParameters(); + searchParameters.FirstSolutionStrategy = + FirstSolutionStrategy.Types.Value.PathCheapestArc; + Assignment solution = routing.SolveWithParameters(searchParameters); + // 0 --(+1)-> 1 --(+1)-> 2 --(+1)-> 3 --(+1)-> 4 --(+4)-> 0 := +8 + Assert.Equal(8, solution.ObjectiveValue()); + } + } +} // namespace Google.OrTools.Tests + diff --git a/examples/tests/RoutingSolverTests.csproj b/examples/tests/RoutingSolverTests.csproj new file mode 100644 index 0000000000..cf480c909b --- /dev/null +++ b/examples/tests/RoutingSolverTests.csproj @@ -0,0 +1,24 @@ + + + Exe + 7.2 + netcoreapp2.1 + false + Google.OrTools.RoutingSolverTests + + false + ../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json + + + + full + + + + + + + + + + diff --git a/makefiles/Makefile.dotnet.mk b/makefiles/Makefile.dotnet.mk index 7e6f3c00b8..7ed7f74583 100644 --- a/makefiles/Makefile.dotnet.mk +++ b/makefiles/Makefile.dotnet.mk @@ -578,6 +578,7 @@ 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/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