简体   繁体   中英

ReifiedConstraint in Minizinc

I have a list of tasks and there are some interdependence between them. 9 tasks. 6 cpu 2 from each cpu group. there are three group p1,p2,p3.

cost p1=4
COST p2=5
COST P3=2

Execution time for different task on different cpu is given. We have to transferdata data between tasks. We are going to use point to point link. We need to buy buy a point to point link between two cpu and it will cost us 1. we can reuse these links later.

problem: I want to specify these constraints. r1!=r4 <=> b14=1; b14 r1!=r4 <=> b14=1; b14 is communication time for communication between task 1 and 4. I also need to have a cost for the links. r1: cpu task one is assigned to.

if r1!=r4 then cost[r1][r4]=1;

Can anyone show me how i can specify these two constraints in Minizinc? I don't want to use if then constraint if i can use reified everything it would be better.

In MiniZinc, you can't use "if condition then ... else ... endif" when the condition involves decision variables. Instead reifications must then be used and they are stated using "->", "<-" and "<->":

   c1 -> c2   implication
   c2 <- c1   implication (same as c1 -> c2) 
   c1 <-> c2   equivalence

So, the two constraints should be written like this (assuming that "r1" and "r4" are decision variables):

constraint 
     (r1 != r4 <-> b14=1) 
     /\
     (r1 != r4 -> cost[r1,r4] = 1)
;

Always put parenthesis around the reifications when working with more than one constraints in a "constraint" section, otherwise the parser may interpret the constraints the wrong way.

Also, note that an element in a matrix are written as

   cost[r1,r2]

That said, if you can use if/then/else/endif construct, then you probably should do that since translating a reification is normally more costly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM