I’m quite new to alloy and currently reading the tutorials at mit. I got a little stuck in the logic of things. A very basic thing i’m trying to do is below.
- a person can only do at most 1 task
- a task can be done at most by 1 person
- a person can only do what s/he is able to
When i run the following, everyone has the same skills(all skills) and every task requires the same skills (all again). The people at least get assigned 1 task each but they get the same task sometimes.
thanks in advance
some sig Skills{ }
some sig Person {
has: some Skills,
assigned: lone Task
}
some sig Task
{
requires: some Skills
}
{
// everyone must have the required task skills for assignment
all p:Person | p.has= requires
}
pred Valid ()
{
//everyone must be assigned to single task
all p:Person | lone t:Task| p.assigned in t
// no one can have the same task
no p1:Person , p2:Person | p1.assigned not in p2.assigned
}
run Valid
There are a number of things that are incorrect in your model.
To implement this, the
lonemultiplicity modifier for theassignedfield in thePersonsignature is sufficient. If you want every person to have exactly one task assigned, you can changelonetoone.Your constraint in the
Validpredicate is wrong because instead ofp1.assigned not in p2.assignedyou should writep1.assigned = p2.assignedin order to say that there are no two persons that have the same task assigned. Additionally you should add a constraint that ensures thatp1 != p2. Alternatively, you could writeall p1, p2: Person | p1 != p2 implies p1.assigned != p2.assigned. Finally, to avoid having to writep1 != p2in the quantifier body, you can use thedisjkeyword to say, e.g.,no disj p1, p2: Person | p1.assigned = p2.assigned, orall disj p1, p2: Person | p1.assigned != p2.assigned.Your constraint in the appended facts section of the
Tasksignature is wrong because it doesn’t mention theassignedfield at all, which is what you must do in order to say thatfor each person and the task assigned to them, the person has all the skills required by the task. What you wrote means that for every task, every person has all the skills required by that task. The only way to satisfy that, is if all tasks have the same set of skills, which is exactly what you noticed in all instances you were getting for your model.
Here is how I would model this (note the slight changes in field and signature names, which makes the model slightly more readable and understandable):