not able to use AddMaxEquality

302 views
Skip to first unread message

Rishabh Mohan

unread,
Aug 21, 2019, 9:16:27 AM8/21/19
to or-tools-discuss


Can someone tell why my AddMaxEquality function not working?





#91 utility numbers for a grid of 3 by 3, for each origin cell to destination cell, so total 81 utility numbers 

a = np.random.randint(0, 10, size=(9,9))



model = cp_model.CpModel()


#each cell in grid is either 0 or 1

cell_binary = [model.NewBoolVar("Cell_" + str(i)) for i in range(9)]



model.Add(sum(cell_binary) == 2)


#list of list of utility numbers for all cells 

utilities = [

    [

        model.AddProdEquality(

            model.NewIntVar(0, 100, “j”),

            [a[o, d], cell_binary[o]],

        )

        for o in range(9)

    ]

    for d in range(9)

]


#find max utility 

utility_max = [

    model.AddMaxEquality(model.NewIntVar(0, 10, "a"), i)

    for  i in utilities

] 

Laurent Perron

unread,
Aug 21, 2019, 9:24:46 AM8/21/19
to or-tools-discuss
API is

model.AddMaxEquality(target_variable, [x1, .., xn])

where xi and target_variable are variables.

It enforces

target_variable = max(x1, .., xn)
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/e320f746-f1d4-4d60-978c-b4cf3da72d85%40googlegroups.com.

Rishabh Mohan

unread,
Aug 21, 2019, 12:07:20 PM8/21/19
to or-tools-discuss
 Thanks, so, what should I do differently that it will work?
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.

Laurent Perron

unread,
Aug 21, 2019, 12:28:03 PM8/21/19
to or-tools-discuss
The sub-arrays of utilities must be arrays of variables.
In your code, these are arrays of constraints.

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


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/fdace77b-0e9e-4a08-bc73-b9a3fbf868a8%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages