diff --git a/bomb_problems/bmtc.lp b/bomb_problems/bmtc.lp new file mode 100644 index 0000000..4d32f34 --- /dev/null +++ b/bomb_problems/bmtc.lp @@ -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). diff --git a/bomb_problems/bmtuc.lp b/bomb_problems/bmtuc.lp new file mode 100644 index 0000000..6621647 --- /dev/null +++ b/bomb_problems/bmtuc.lp @@ -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). diff --git a/bomb_problems/create_instances.py b/bomb_problems/create_instances.py new file mode 100644 index 0000000..4e01523 --- /dev/null +++ b/bomb_problems/create_instances.py @@ -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")