Current cumul value of from_node in the dimension callback

223 views
Skip to first unread message

Hanu

unread,
Jul 26, 2021, 2:27:20 PM7/26/21
to or-tools-discuss
Is there any way to get the curent cumul value of the counter dimension of current vehicle during the callback?


    // Add Max node counter dimension.
    const int nodes_served_callback_index = routing.RegisterTransitCallback(
        [&model, &manager](int64 i, int64 j) -> int64 {
            auto from_node = manager.IndexToNode(i).value();
            auto to_node = manager.IndexToNode(j).value();
            Is there any way to get how many nodes served when node 'i' is called in the callback?   
            return 1;
        });

    routing.AddDimension(
        nodes_served_callback_index,    // transit callback index
        0,                 // null  slack
        max_nodes_to_serve,  // max nodes to serve is 10
        true,                      // start cumul to zero
        "Counter");


Thanks

Gilberto Kaihami

unread,
Jul 26, 2021, 3:54:57 PM7/26/21
to or-tools-discuss
Hello,

Have you tried the CumulVar?

```
...
counter_dimension = routing.GetDimensionOrDie("Counter")
for vehicle_id in range(manager.GetNumberOfVehicles()):
     index = routing.End(vehicle_id)
     counter_cumul = counter_dimension.CumulVar(index)
     ....
```


Cheers,

Hanu

unread,
Jul 27, 2021, 1:35:50 AM7/27/21
to or-tools-discuss
Hi,

I tried that but it crashes the execution as below:

fetching cumul value for vehicle = 0
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0727 10:58:17.616341  2322 expressions.cc:1340] Check failed: min_.Value() == max_.Value() (0 vs. 7)  variable Counter14(0..7) is not bound.
*** Check failure stack trace: ***



Here is the code that was executed:

 // Add Max node counter dimension.
    const int nodes_served_callback_index = routing.RegisterTransitCallback(
        [&routing, &model, &manager](int64 i, int64 j) -> int64 {
            auto from_node = manager.IndexToNode(i).value();
            auto to_node = manager.IndexToNode(j).value();

        const RoutingDimension& counter_dimension =  routing.GetDimensionOrDie("Counter");

            for (int vehicle_id = 0; vehicle_id < model.num_vehicles; vehicle_id++) { 
                int index = manager.GetEndIndex(vehicle_id);//routing.End(vehicle_id);
                printf("fetching cumul value for vehicle = %d\n", vehicle_id);
                printf("counter_dimension value = %ld for vehicleId = %d\n", counter_dimension.CumulVar(index)->Value()); 
            }

            return 1;
        });

    routing.AddDimension(
        nodes_served_callback_index,    // transit callback index
        0,                 // null  slack
        max_nodes_to_serve,  // max nodes to serve is 10
        true,                      // start cumul to zero
        "Counter");




.

Laurent Perron

unread,
Jul 27, 2021, 2:20:00 AM7/27/21
to or-tools-discuss
No. The evaluators must be stateless. 

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/458ef49f-2d7d-4a64-ba75-a3f6985cfa0dn%40googlegroups.com.

Mizux Seiha

unread,
Jul 27, 2021, 8:09:28 AM7/27/21
to or-tools-discuss
+ the evaluator values may be cached so it must be a deterministic function

Hanu

unread,
Jul 27, 2021, 8:35:13 AM7/27/21
to or-tools-discuss
Ok got it. Thanks a lot for quick responses.
Reply all
Reply to author
Forward
0 new messages