Adding Penalties

451 views
Skip to first unread message

Antonia Calvi

unread,
Jun 26, 2018, 6:46:19 AM6/26/18
to or-tools-discuss
I have a cumulative variable over a large horizon.
I would like to penalise if its modulus is outside of a certain range.
I was thinking of iterating through the different nodes and creating conditional expressions with the solver which would assign say an IntVar(0) if it is within the range, otherwise a penalty of 50.
I would then like another variable to store the sum of the overall penalties and then add that to minimise the finaliser - this however does not seem to change anything.
My output does not seem to take account of the penalties.
I am also unsure how to iteratively add to an IntVar... any suggestions?

I use python btw

Laurent Perron

unread,
Jun 26, 2018, 6:58:28 AM6/26/18
to or-tools-discuss
My understanding

Horizon 100
Cumulative, safe level 8, max level 10
You want to penalize by 50 if you are above the safe level on each quarter of the horizon 

Create 4 optional intervals with fixed dated (start = 0, duration = 25, presence = lit0; start = 25, duration = 25, presence = lit1, ...). 
Add them to the cumulative.

Create negation of lit0, lit1, lit2, lit3

Add 50 * lit_i to the objective.
Does it solve your problem?

--Laurent
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
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.
For more options, visit https://groups.google.com/d/optout.

Laurent Perron

unread,
Jun 26, 2018, 7:22:08 AM6/26/18
to or-tools...@googlegroups.com
I meant add 50 * not_lit_i to the objective.

Antonia Calvi

unread,
Jun 26, 2018, 7:36:25 AM6/26/18
to or-tools-discuss
I don't really follow your reasoning.. what I am having is a routing problem, my time horizon is within a few day, but I want to penalise if a vehicle arrives within closing hours at a specific day - hence taking the modulus.

right now what I have is something of the sort:

sl = solver.IntVar(0, 0)

    for cust in customers.customers:
        if (cust.tw_open is not None) and (cust.tw_close is not None):
       
            less1 = solver.ConditionalExpression(solver.IsGreaterOrEqualCstVar(((time_dimension.CumulVar(routing.NodeToIndex(cust.index)))%86400),28000).Var(), solver.IntVar(0,0), 50).Var()
         
            more1 = solver.ConditionalExpression(solver.IsLessOrEqualCstVar((time_dimension.CumulVar(routing.NodeToIndex(cust.index))%86400),28800).Var(), solver.IntVar(0,0), 50).Var()
            
            slack = solver.Max(less1, more1).Var()

            sl=solver.Sum([sl,slack]).Var()
            solver.Minimize(sl,1)
 


    routing.AddVariableMinimizedByFinalizer(sl)

Antonia Calvi

unread,
Jun 26, 2018, 7:36:55 AM6/26/18
to or-tools-discuss
Also.. in routing problems how do you add directly to the objective? I have found difficulty doing this..

Laurent Perron

unread,
Jun 26, 2018, 8:27:55 AM6/26/18
to or-tools-discuss
I was proposing a scheduling solution with the CP-SAT solver.
You want a feature of the routing library. Please forget my suggestion.

--Laurent
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Antonia Calvi

unread,
Jun 26, 2018, 8:31:44 AM6/26/18
to or-tools-discuss
You don't happen to have suggestions do you?

Laurent Perron

unread,
Jun 26, 2018, 10:29:16 AM6/26/18
to or-tools...@googlegroups.com
No, I will let the routing expert answer you :-)

Samir Sabri

unread,
Jun 26, 2018, 10:42:23 AM6/26/18
to or-tools...@googlegroups.com
Thanks :)
--
Kind Regards,
--------------------------------------------- 
Samir Sabri
Software Architect& Developer
Jordan-Middle East
Reply all
Reply to author
Forward
0 new messages