How to write constraint involving a certain parameter in clingo?

484 Views Asked by At

I am attempting to solve the Google ASP Competition 2019 : Insurance Referee Assignment problem. The problem is provided in this link.

There is a hard constraint that if a referee has preference type of 0 then the case will not be assigned to that referee. I have simplified the problem to include a few variables.

case(cid) refers to a case with cid as the case id.
ref(rid) refers to the referee with referee id.

pref(rid, type) takes the preference of referee 'rid' and type which takes value from 0 to 3. The higher the number, the more likely it will take the case.

In ref(10, 3) and ref(9, 2), the higher preference will be given to ref(10).

I have tried the following clingo code:

ref(rid).
case(cid).
pref(rid, type).

assign(cid, rid) :- ref(rid), pref(rid, type), type != 0.

case(4).

ref(3).
ref(5).

pref(3, 0).
pref(5, 1).

#show assign/2.

However, when I run the command, it shows satisfiable but outputs only this

assign(cid, rid)

What am I doing wrong?

1

There are 1 best solutions below

0
On

In clingo variables start with a capital letter and are "valid" just withhin the rule. So my guess is you want the following code:

assign(Rcid, Rrid) :- case(Rcid), ref(Rrid), pref(Rrid, Rtype), Rtype != 0.

case(4).    
ref(3).    ref(5).
pref(3, 0).    pref(5, 1).
#show assign/2.

output:

Solving...
Answer: 1
assign(4,5)
SATISFIABLE

Please note that only renaming the constants to variable names will result in an error message, you have to add case(Rcid) to the rule body as well. Variable names were freely choosen, you can use any variable name as long as it starts with a capital letter.