CP- Cumulative Constraint

836 views
Skip to first unread message

Andres Collart

unread,
Nov 26, 2015, 1:08:59 PM11/26/15
to or-tools-discuss
Hi,

I'm new to CP and am having some issues getting the Cumulative constraint working properly. Any guidance is really appreciated. I'm solving a RCPSP.


solver = pywrapcp.Solver('Problem')

#Vars
S=[solver.FixedDurationIntervalVar(0,LS[a],Duration[a],False,\
        "S_%s"%a) for a in A]

#Objective
Cmax=solver.Max([S[a].EndExpr() for a in A])


print "Adding Precedence Constraint" , time.clock()
#Add Precedence
for (a,aa) in Prec:
    #solver.Add(S[aa].StS[a].EndExpr()<= S[aa])
    solver.Add(S[aa].StartsAfterEnd(S[a]))


print "Adding Resource Constraints", time.clock()
for r in set(R).intersection(set(r_more)):
    ss=[S[a] for a in A if Demand[a,r]>0]
    #dd=[Duration[a] for a in A if Demand[a,r]>0]
    rr=[Demand[a,r] for a in A if Demand[a,r]>0]
    solver.Cumulative(S, rr, Budget[r])


When it gets to this last line it errors out with the following code: NotImplementedError: Wrong number or type of arguments for overloaded function 'Solver_Cumulative'. 

I've checked a few examples but not sure how to get it working properly. Thanks in advance.

Andres Collart

unread,
Nov 30, 2015, 9:36:07 AM11/30/15
to or-tools-discuss
Still unable to get Cumulative working on this, any help is much appreciated.

Thank you,
Andres

Laurent Perron

unread,
Dec 1, 2015, 9:19:39 AM12/1/15
to or-tools-discuss
Here is a correct example:

def test_cumulative_api():
  solver = pywrapcp.Solver('Problem')

  #Vars
  S=[solver.FixedDurationIntervalVar(0, 10, 5,False, "S_%s"%a)
     for a in range(10)]

  C = solver.IntVar(2, 5)

  D = [a % 3 + 2 for a in range(10)]

  solver.Add(solver.Cumulative(S, D, C, "cumul"))

You need to name your cumulative constraints, like the disjunctive ones. "" is OK.

--
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

Andres Collart

unread,
Dec 4, 2015, 2:39:43 PM12/4/15
to or-tools-discuss
Thanks Laurent, that really clears things up and I've got it working now.

-Andres
Reply all
Reply to author
Forward
0 new messages