Access violation exception

539 views
Skip to first unread message

anu

unread,
Sep 28, 2021, 9:10:35 AM9/28/21
to or-tools-discuss
I am trying to update the version of or tools we are using, we are currently at 6.9 and trying to get it to the latest. However, i am receiving a fatal error below 
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE.Solver_Solve__SWIG_0(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef)
   at Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE.Solver_Solve__SWIG_0(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef)
   at Google.OrTools.ConstraintSolver.Solver.Solve(Google.OrTools.ConstraintSolver.DecisionBuilder, Google.OrTools.ConstraintSolver.SearchMonitorVector)


But, if i change the SetSpanUpperBoundForVehicle to a soft constraint to use setcumulvarsoftupperbound, then i do not get the accessviolationexception. Did anyone have a similar issue before? Thank You.

anu

unread,
Sep 28, 2021, 2:20:38 PM9/28/21
to or-tools-discuss
Actually, the error happens irrespective of using  setcumulvarsoftupperbound or  SetSpanUpperBoundForVehicle. 

Mizux Seiha

unread,
Sep 28, 2021, 2:49:30 PM9/28/21
to or-tools-discuss
Just to be sure using the last version v9.0 in C# (platform will be appreciated) you have some issue when trying to use `SetSpanUpperBoundForVehicle()`

anu

unread,
Sep 29, 2021, 7:59:15 AM9/29/21
to or-tools-discuss
Yes, v9.0 in C# (.net core 3.1)
So, I changed the SetSpanUpperBoundForVehicle() to this.solver.GetDimensionOrDie(dimension).CumulVar(this.solver.End(c)).SetMax(limit); and it looks to work without throwing the access violation exception.

But, there is one more path that fails for the same dimension where i set this.solver.GetDimensionOrDie(dimension).SetSpanCostCoefficientForVehicle(coefficient, c);
Also, just as a note this worked with version 6.9 and fails on any version after that.

Thank you for looking into it.

Mizux Seiha

unread,
Sep 30, 2021, 2:51:31 AM9/30/21
to or-tools-discuss
I don't remember any .Net sample/test using SetSpanUpperBoundForVehicle() or SetSpanCostCoefficientForVehicle() so a regression since 6.9 and having these methods broken in C# is not surprising...

On my way to do some test and check the SWIG generated file if I can find some clue...

Mizux Seiha

unread,
Sep 30, 2021, 4:19:48 AM9/30/21
to or-tools-discuss
Strange using master and hacking constraint_solver/samples/VrpTimeWindows.cs here  https://github.com/google/or-tools/blob/b37d9c786b69128f3505f15beca09e89bf078a89/ortools/constraint_solver/samples/VrpTimeWindows.cs#L160

```cs
        for (int i = 0; i < manager.GetNumberOfVehicles(); ++i) {
            timeDimension.SetSpanUpperBoundForVehicle(22, i);
        }
```
seems to work:
```sh
make rdotnet_VrpTimeWindows
...
Time Elapsed 00:00:00.78
"/usr/bin/dotnet" run --no-build  --project ortools/constraint_solver/samples/VrpTimeWindows.csproj
Objective 71:
Route for Vehicle 0:
0 Time(0,0) -> 9 Time(2,3) -> 14 Time(7,8) -> 16 Time(11,11) -> 0 Time(18,18)
Time of the route: 18min
Route for Vehicle 1:
0 Time(0,0) -> 12 Time(4,4) -> 13 Time(6,6) -> 15 Time(11,11) -> 11 Time(14,14) -> 0 Time(20,20)
Time of the route: 20min
Route for Vehicle 2:
0 Time(2,2) -> 7 Time(4,4) -> 1 Time(8,11) -> 4 Time(10,13) -> 3 Time(16,16) -> 0 Time(24,24)
Time of the route: 24min
Route for Vehicle 3:
0 Time(0,0) -> 5 Time(3,3) -> 8 Time(5,5) -> 6 Time(7,7) -> 2 Time(10,10) -> 10 Time(14,14) -> 0 Time(20,20)
Time of the route: 20min
Total time of all routes: 82min
make[1]: Leaving directory '/home/mizux/work/master'
```
note: On vehicle 2 we can see start is now (2,2) while it was (0,0) before the change...
note2: I've also looked at the ortools/gen/ortools/constraint_solver/RoutingDimension.cs nothing seems strange

So I would say SetSpanUpperBoundForVehicle() is working as expected at least on master branch.

Mizux Seiha

unread,
Sep 30, 2021, 4:26:42 AM9/30/21
to or-tools-discuss
Same story for SetSpanCostCoefficientForVehicle() ...

```cs
      for (int i = 0; i < manager.GetNumberOfVehicles(); ++i) {
            timeDimension.SetSpanUpperBoundForVehicle(22, i);
            timeDimension.SetSpanCostCoefficientForVehicle(/*coefficientt=*/1+i, i);
        }
```

```sh
make rdotnet_VrpTimeWindows
...
Time Elapsed 00:00:00.78
"/usr/bin/dotnet" run --no-build  --project ortools/constraint_solver/samples/VrpTimeWindows.csproj
Objective 254:
Route for Vehicle 0:
0 Time(2,2) -> 7 Time(4,4) -> 1 Time(8,8) -> 4 Time(13,13) -> 3 Time(16,16) -> 0 Time(24,24)
Time of the route: 24min
Route for Vehicle 1:
0 Time(1,1) -> 12 Time(5,5) -> 13 Time(7,7) -> 15 Time(12,12) -> 11 Time(15,15) -> 0 Time(21,21)
Time of the route: 21min
Route for Vehicle 2:
0 Time(1,1) -> 9 Time(3,3) -> 5 Time(5,5) -> 6 Time(7,7) -> 2 Time(10,10) -> 10 Time(14,14) -> 0 Time(20,20)
Time of the route: 20min
Route for Vehicle 3:
0 Time(2,2) -> 8 Time(5,5) -> 14 Time(8,8) -> 16 Time(11,11) -> 0 Time(18,18)
Time of the route: 18min
Total time of all routes: 83min
make[1]: Leaving directory '/home/mizux/work/master'
```
note: objective is correctly updated, smaller id vehicle have longer route (since coefficient value is linear to the vehicle id)

last possibility is the nuget package is broken but I can see why...
Reply all
Reply to author
Forward
0 new messages