Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefandinno committed Oct 6, 2023
1 parent 0e337a5 commit 100ae55
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
55 changes: 55 additions & 0 deletions bomb_problems/bmtc.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% arguments %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% input: input_length(L).
% input: input_toilet(T).
num_packages(L/2) :- input_length(L).
max_length(L-1) :- input_length(L).
toilet(1..T) :- input_toilets(T).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% initial states %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

package(1..NP) :- num_packages(NP).

{ holds(armed(P),0) } :- package(P).
:- not 1 { holds(armed(P),0) : package(P) } 1.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% problem description %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%% fluents %%%%%%%%%%%%%%%%%%

fluent(armed(P)) :- package(P).
inertial(armed(P)) :- package(P).

fluent(dunked(P)) :- package(P).
inertial(dunked(P)) :- package(P).

fluent(clogged).
inertial(clogged).

fluent(unsafe).

%%%%%%% actions %%%%%%%%
action(dunk(P,L)) :- package(P), toilet(L).
action(flush(L)) :- toilet(L).

%%%%%% executable %%%%%%%
executable(dunk(P,L), S) :- action(dunk(P,L)), toilet(L), not holds(clogged(L),S), step(S).

executable(flush(L), S) :- action(flush(L)), toilet(L), step(S).

%%%%% direct effects %%%%%%%
-holds(armed(P), T+1) :- occurs(dunk(P,L), T), step(T).
holds(dunked(P), T+1) :- occurs(dunk(P,L), T), step(T).
1{ -holds(clogged, T+1) ; holds(clogged, T+1)}1 :- occurs(dunk(P,L), T), toilet(L), step(T).

-holds(clogged(L), T+1) :- occurs(flush(L), T), toilet(L), step(T).

%%%%% indirect effects %%%%%%%
holds(unsafe, T) :- holds(armed(P), T), step(T).
-holds(unsafe, T) :- not holds(unsafe, T), step(T).
55 changes: 55 additions & 0 deletions bomb_problems/bmtuc.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% arguments %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% input: input_length(L).
% input: input_toilet(T).
num_packages(L/2) :- input_length(L).
max_length(L-1) :- input_length(L).
toilet(1..T) :- input_toilets(T).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% initial states %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

package(1..NP) :- num_packages(NP).

{ holds(armed(P),0) } :- package(P).
:- not 1 { holds(armed(P),0) : package(P) } 1.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% problem description %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%% fluents %%%%%%%%%%%%%%%%%%

fluent(armed(P)) :- package(P).
inertial(armed(P)) :- package(P).

fluent(dunked(P)) :- package(P).
inertial(dunked(P)) :- package(P).

fluent(clogged).
inertial(clogged).

fluent(unsafe).

%%%%%%% actions %%%%%%%%
action(dunk(P,L)) :- package(P), toilet(L).
action(flush(L)) :- toilet(L).

%%%%%% executable %%%%%%%
executable(dunk(P,L), S) :- action(dunk(P,L)), toilet(L), not holds(clogged(L),S), step(S).

executable(flush(L), S) :- action(flush(L)), toilet(L), step(S).

%%%%% direct effects %%%%%%%
-holds(armed(P), T+1) :- occurs(dunk(P,L), T), step(T).
holds(dunked(P), T+1) :- occurs(dunk(P,L), T), step(T).
holds(clogged(L), T+1) :- occurs(dunk(P,L), T), toilet(L), step(T).

-holds(clogged(L), T+1) :- occurs(flush(L), T), toilet(L), step(T).

%%%%% indirect effects %%%%%%%
holds(unsafe, T) :- holds(armed(P), T), step(T).
-holds(unsafe, T) :- not holds(unsafe, T), step(T).
25 changes: 25 additions & 0 deletions bomb_problems/create_instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import sys

script_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
instances_directory = os.path.join(script_directory, "instances")

os.makedirs(instances_directory, exist_ok=True)

for i in range(10, 160, 10):
print(f"Creating instance {i:04d}")
instance_path = os.path.join(instances_directory, f"bomb_{i:04d}.lp")
with open(instance_path, "w") as f:
f.write(f"input_length({i}).\n")

instances_directory = os.path.join(script_directory, "instances_many")

os.makedirs(instances_directory, exist_ok=True)

for i in range(10, 160, 10):
for t in range(1, 5):
print(f"Creating instance {i:04d}_{t:02d}")
instance_path = os.path.join(instances_directory, f"bomb_{i:04d}_{t:02d}.lp")
with open(instance_path, "w") as f:
f.write(f"input_length({i}).\n")
f.write(f"input_toilets({t}).\n")

0 comments on commit 100ae55

Please sign in to comment.