summaryrefslogtreecommitdiff
path: root/food_delivery/generate-food.py
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-01-13 18:18:51 +0100
committerPeter Wu <peter@lekensteyn.nl>2017-01-13 18:18:51 +0100
commit2b84767d5b493bde658b443637b8733cfaf57a34 (patch)
treef0dd8c59349636cb6f4b38596033cc3e3bc64a4d /food_delivery/generate-food.py
parentd1416bd2cb9651f3de7c12da3d8133d0287db5c3 (diff)
download2IMF25-AR-2b84767d5b493bde658b443637b8733cfaf57a34.tar.gz
FoodDelivery: improve solution for b
Now requires truck to return to a location, also accept any location instead of just the supply location S.
Diffstat (limited to 'food_delivery/generate-food.py')
-rwxr-xr-xfood_delivery/generate-food.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/food_delivery/generate-food.py b/food_delivery/generate-food.py
index dc87c03..192131b 100755
--- a/food_delivery/generate-food.py
+++ b/food_delivery/generate-food.py
@@ -118,17 +118,22 @@ for j in range(1, m + 1):
preds += ["(or %s)" % "\n".join(altpreds)]
if is_b:
- # If stock is higher or equal to initial state, then we found a loop.
+ # If any stock is higher or equal to another state in the same location,
+ # then we found a loop.
stuff = []
- for j in range(1, m + 1):
- jprev = j - 1
- highers = " ".join([
- "(>= s{i}_{j} s{i}_0)".format(i=i, j=j)
- for i in range(1, len(states))
- ])
- stuff += fillin([
- "(and {highers})"
- ], vars())
+ literals += ["k0", "k1"]
+ for k in range(1, m + 1):
+ for j in range(1, m + 1):
+ if k >= j:
+ continue
+ jprev = j - 1
+ highers = " ".join([
+ "(>= s{i}_{j} s{i}_{k})".format(i=i, j=j, k=k)
+ for i in range(1, len(states))
+ ])
+ stuff += fillin([
+ "(and {highers} (= l{j} l{k}) (= k0 {j}) (= k1 {k}))"
+ ], vars())
preds += ["(or %s)" % " ".join(stuff)]