Then we need the potion prerequisites.

>> Mm-hm.

>> Now that's pretty easy with the day variables, so

we just say okay, this is the one that has to be finished first.

Then it has to be on a day, that's before the day where we do the second.

Okay?

We can also map it using these boolean variables, right?

So basically this is calculating the day when the first one was done.

And this is calculated in the day when the second was done, and

making the same constraint, it ends up being a linear constraint.

We can also do it with the SET variables, it's a bit trickier, all right.

So we're basically saying okay, if we look at all the days and

we have that this portion is done on day d1, right.

Then if we look at all the days before d1,

then we can't have the second portion done on that day.

>> Wow, in this way of expressing the constraint, we are using if then.

>> Yep. >> And we are also using negation.

>> Well yeah, a negation of a boolean isn't too bad.

>> Okay. >> Okay.

>> Yeah.

>> Yeah so it's bad, but it's not too bad.

>> So essentially we have three different

ways of making use of the three kinds of decision variables to express

the constraint. >> Yeah, the is a constraint.

>> Right.

>> Right, they're all there at the moment.

>> Yeah.

>> Right and we're going to do that for

every one of the constraints for the problem.

Okay, so we have to keep track of the number of potions we've made in each day.

>> Yeah. >> Right,

so we can do this by just summing up for every potion,

right, if it's made in that day.

Okay, so that's obvious way of doing it.

Very similar if I've got the booleans.

I'm just summing up the 01s of which potions are on that day.

>> Yep.

>> But if I have the potions, right, which actually gives me the set.

I just need to get the cardinality, right.

So it's simpler, this is simple in the SetView.

All right, what about the calculation of how many alchemists are working each day,

it's very similar as to what we did before.

Here we're just saying if we do this potion on this day,

then we have to have at least this many alchemists that portion needs.

And that gives us the total working on that day.

So I'm summing across all potions.

Very, very similar in the boolean view, right?

>> It's just that this expression here day(p)=d is exactly equivalent

to this potion, potion_day[p,d].

And for the SetView, we can actually make use of a global constraint,

which is isn't normally visible, but it is available.

And this is basically something which given the set, and it says for

each of the elements, so the potion is the set of elements and alchemy is the weight

of each element, it's going to calculate the weight of elements in that set.

>> Wow. >> Okay, so

this is exactly what this global constraint does, and we're going to need

to have this definition here, just to make sure that it gets through the flat sync.

>> It's a predicate.

>> Exactly, the solver g-code understands this constraint.

>> So in this exercise here, we can really see the power of multiple modeling, right?

I mean it allows us to look at the problem from different viewpoints.

>> Exactly. >> And we can also see that some

of the constraints are easier to express in a particular viewpoint.

>> Exactly.

>> Right.

>> All right, so then we've got some more constraints.

So potions are not assigned to two days.

Okay, so that's obvious in the day view, right?

>> Right. >> Because the day view,

I look at the potion, it's given a day.

It can't be given two days.

>> Exactly.

>> So that always happens.

Not obvious for the other ones.

So for the boolean view, well, I sum across all the days and

I say the number of days when I make this potion has to be equal to one,

which means only one day can be true.

And for the SetView, I basically need that the sets for each day,

they all have to be disjoined.

So that's the global distraint, all disjoined.

>> So a potion cannot appear in more than one set.

>> Exactly. >> Yeah.

>> Basically two sets have to be disjoined >> All right,

now remember we've got multiple viewpoints so we have to make them agree.

>> Yeah.

>> So if we're going to use two viewpoints we have to make them agree.

We can channel between day and potion day.

>> Yeah.

>> And this is basically exactly the statement we said.

Potion day pd is exactly the same statement as saying the day that I made

potion p was d.

>> Yeah.

>> Right, we can channel between potion day and the potion view,

which is almost the same, right?

If I made potion p on day d,

then it was p is in the potions that are made on day d, right?

And for this SetView and the assignment view,

then we have this int_set_channel, which does exactly that.

>> Global constraint.

>> Exactly, because this is a common thing that happens in mobile.

Right, so we have it.

So, just no, nothing wrong with not having global constraint here because in fact,

there's not much you can do better than these definitions, right?

>> Sure. >> Okay, we're also,

in order to make our model strong, we're going to add some redundant constraints.

So here it's just making sure that if we add up all the amounts of working on

the days, it gets the total alchemy we need to do,

which is the sum of an alchemy of all the portions.

And basically if we add up all the numbers we have to get to the number of

portions, right?

So that's basically just redundant constraints.

Here's a tricky one and this is looking for everyday, we're sort of

looking at the number of portions that are made after this day, right?