I am writing code for the London tube. I have declared facts that display the name of a station and also which line it is on. e.g.
station(aldgate,metropolitan).
station(brixton,victoria).
station(baker,metropolitan).
I'm trying to work out a rule that will check whether two stations are on the same line, and which line that is. For example, aldgate
and baker
are on the same line, metropolitan
.
Any ideas?
An example can be the following rule
that is flexible.
It can check of a couple of station is in the same line (calling
sameLine(aldgate, baker, metropolitan)
return true, callingsameLine(aldgate, baker, Line)
return true and unifyLine
withmetropolitan
) but can find couples of stations of a line (callingsameLine(Stat1, Stat2, metropolitan)
return true two times, unifyingStat1
withaldgate
andStat2
withbaker
(the first time) and vice versa (the second time)).Observe the constraint
It's to impose that the two stations are different.
If you want that
sameLine(aldgate, aldgate, Line)
return true unifyingLine
withmetropolitan
, you can delete it.If you, otherwise, want to avoid the double results (
aldgate
/baker
andbaker
/aldgate
, by example, callingsameLine(Stat1, Stat2, metropolitan)
) you can impose thatStat1
is non only different thanStat2
but also that is "before"Stat2
, replacingwith
But, in this way, you obtain true from
sameLine(aldgate, baker, Line)
, but false (becausebaker
isn't "before"aldgate
) fromsameLine(baker, aldgate, Line)
.