-
-
Save hwayne/c2e7d928d16de4ce3d117cf2e45d464d to your computer and use it in GitHub Desktop.
Picat example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cp. | |
| import util. | |
| day(1) = wed. | |
| day(2) = thurs. | |
| day(3) = fri. | |
| day(4) = sat. | |
| day(5) = sun. | |
| clearsky(3). | |
| clearsky(4). | |
| car(pinnacles). | |
| car(thetis). | |
| car(mauritian). | |
| allday(freemantle). | |
| allday(rottnest). | |
| allday(thetis). | |
| outofcity(Day, Sched) => Sched.get(rottnest) = Day. | |
| outofcity(Day, Sched) => | |
| carday(Day, Sched), | |
| carday(D2, Sched), | |
| D2 > Day. | |
| food(mauritian). | |
| incompat(freemantle, kingspark). | |
| incompat(mint, kingspark). | |
| incompat(Act, CarAct) :- | |
| member(Act, [freemantle, rottnest]), | |
| car(CarAct). | |
| incompat(AllDayAct, Other) :- | |
| allday(AllDayAct), | |
| not minor(Other). | |
| minor(Act) => food(Act); Act = stargazing. | |
| dayfor(Event, Sched) = Sched.get(Event). | |
| diffdays(Act1, Act2, Sched) => | |
| dayfor(Act1, Sched) != dayfor(Act2, Sched). | |
| incompat_rule(Sched) => | |
| foreach(I in Sched.keys, J in Sched.keys, I != J) | |
| if incompat(I, J) then diffdays(I, J, Sched) end | |
| end. | |
| carday(Day, Sched) ?=> | |
| car(X), | |
| dayfor(X, Sched) = Day. | |
| car_rule(Sched) => | |
| not ( | |
| carday(D1, Sched), | |
| carday(D2, Sched), | |
| D1 > D2 + 1 | |
| ), | |
| not carday(5, Sched). | |
| stargazing_rule(Sched) => | |
| Starday = dayfor(stargazing, Sched), | |
| outofcity(Starday, Sched), | |
| clearsky(Starday). | |
| schedule(Sched) => | |
| Sched = new_map([pinnacles = D1, thetis = D2, freemantle = D3, rottnest = D4, kingspark = D5, mauritian = D6, mint= D7, stargazing = D8]), | |
| Days = 1..5, | |
| foreach(V in Sched.values) member(V, Days) end, | |
| incompat_rule(Sched), | |
| [D: D in Days, carday(D, Sched)].len == 2, | |
| dayfor(rottnest, Sched).day != sun, | |
| stargazing_rule(Sched), | |
| car_rule(Sched), | |
| nl. | |
| main => | |
| schedule(Sched), | |
| foreach(D in 1..5) | |
| Str = join([to_string(A) : A in Sched.keys, Sched.get(A) = D], ", ") , | |
| writef("%w: %s\n", day(D), Str), | |
| end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cp. | |
| import util. | |
| day(1) = wed. | |
| day(2) = thurs. | |
| day(3) = fri. | |
| day(4) = sat. | |
| day(5) = sun. | |
| clearsky(3). | |
| clearsky(4). | |
| car(pinnacles). | |
| car(thetis). | |
| car(mauritian). | |
| allday(freemantle). | |
| allday(rottnest). | |
| allday(thetis). | |
| outofcity(Day, Sched) => dayfor(rottnest, Sched) = Day. | |
| outofcity(Day, Sched) => | |
| carday(Day, Sched), | |
| carday(D2, Sched), | |
| D2 > Day. % come back this day | |
| food(mauritian). | |
| incompat(freemantle, kingspark). | |
| incompat(mint, kingspark). | |
| incompat(Act, CarAct) :- | |
| member(Act, [freemantle, rottnest]), | |
| car(CarAct). | |
| incompat(AllDayAct, Other) :- | |
| allday(AllDayAct), | |
| not minor(Other). | |
| minor(Act) => food(Act); Act = stargazing. | |
| dayfor(Event, Sched) = Day => member({Event, Day}, Sched). | |
| diffdays(Act1, Act2, Sched) => | |
| dayfor(Act1, Sched) != dayfor(Act2, Sched). | |
| incompat_rule(Sched) => | |
| foreach({A1, D1} in Sched, {A2, D2} in Sched, A1 != A2) | |
| if incompat(A1, A2) then D1 != D2 end | |
| end. | |
| carday(Day, Sched) => | |
| car(X), | |
| member({X, Day}, Sched). | |
| car_rule(Sched) => | |
| not ( | |
| carday(D1, Sched), | |
| carday(D2, Sched), | |
| D1 > D2 + 1 | |
| ), | |
| not carday(5, Sched). | |
| stargazing_rule(Sched) => | |
| Starday = dayfor(stargazing, Sched), | |
| outofcity(Starday, Sched), | |
| clearsky(Starday). | |
| schedule(Sched) => | |
| Sched = [{pinnacles, D1}, | |
| {thetis, D2}, | |
| {freemantle, D3}, | |
| {rottnest, Rottday}, | |
| {kingspark, D5}, | |
| {mauritian, D6}, | |
| {mint, D7}, | |
| {stargazing, D8} | |
| ], | |
| Days = 1..5, | |
| foreach({A, B} in Sched) member(B, Days) end, | |
| incompat_rule(Sched), | |
| [D: D in Days, carday(D, Sched)].len == 2, | |
| day(Rottday) != sun, | |
| stargazing_rule(Sched), | |
| car_rule(Sched), | |
| nl. | |
| main => | |
| schedule(Sched), | |
| foreach(D in 1..5) | |
| Str = [to_string(A) : {A, D} in Sched], | |
| writef("%w: %s\n", day(D), join(Str, ", ")), | |
| end, | |
| nl. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment