Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a1090c0
Update to include test code, realize issues, and clean up unnecessary…
carwyn987 Sep 25, 2025
f023860
Update, identified location of bug that exists within linearize, but …
carwyn987 Sep 27, 2025
31349ba
Add initial layer interference test, recursive goal testing, and appr…
carwyn987 Sep 27, 2025
e2f48d3
Add action application to verify results
carwyn987 Sep 27, 2025
0fb3902
Add changes, stuff doesn't work
carwyn987 Sep 29, 2025
7a3ad7c
I have made the formulation understandable now. Each level is grouped…
carwyn987 Sep 29, 2025
5234d7b
Cake problem works now. On to debugging shopping problem );
carwyn987 Sep 29, 2025
5fbbc85
If I ever see GraphPlan in a dark alley it's not leaving alive. ... b…
carwyn987 Sep 30, 2025
60d33ea
Now I'm confused about some of the tests. ... tennis problem also fai…
carwyn987 Sep 30, 2025
cb71b64
Improved extract_solution
carwyn987 Sep 30, 2025
256863c
Most tests consistently passing
carwyn987 Oct 1, 2025
204b19b
Working! Needed to update the extract_solution to attempt every power…
carwyn987 Oct 4, 2025
ea6ca75
Cleanup
carwyn987 Oct 4, 2025
c6ce67c
Cleanup and pytest configuration work
carwyn987 Oct 5, 2025
a2265d7
Merge pull request #1 from carwyn987/experimental/revert_ordering_and…
carwyn987 Oct 5, 2025
82e061b
More cleanup, removed unnecessary functions
carwyn987 Oct 5, 2025
4a24a2e
Further cleanup
carwyn987 Oct 5, 2025
497414c
Issue identified. Leveloff condition failing to check for mutex equiv…
carwyn987 Oct 5, 2025
b16e862
Differentiated between state and action mutexes. Fixed leveloff funct…
carwyn987 Oct 5, 2025
dabd9bd
Remove lingering print statement
carwyn987 Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update to include test code, realize issues, and clean up unnecessary…
… files
  • Loading branch information
carwyn987 committed Sep 25, 2025
commit a1090c0981cd05451f83b9a9e62a790f346c7ec4
108 changes: 108 additions & 0 deletions linearize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

class Linearize:

def __init__(self, planning_problem):
self.planning_problem = planning_problem

def filter(self, solution):
"""Filter out persistence actions from a solution"""

new_solution = []
for section in solution[0]:
new_section = []
for operation in section:
if not (operation.op[0] == 'P' and operation.op[1].isupper()):
new_section.append(operation)
new_solution.append(new_section)
return new_solution

def orderlevel(self, level, planning_problem):
"""Return valid linear order of actions for a given level"""

for permutation in itertools.permutations(level):
print(f"TRYING PARTIAL PLAN: {permutation}") ## Bill's hack
temp = copy.deepcopy(planning_problem)
count = 0
## print(f"PERMUTATION: {permutation}") ## Bill's hack
for action in permutation:
try:
# print(f"TRY ACTION: {action}") ## Bill's hack
temp.act(action)
count += 1
# print(f"TRY ACTION: {action} SUCCESS!") ## Bill's hack
except:
# print(f"TRY ACTION: {action} FAIL!") ## Bill's hack
count = 0
temp = copy.deepcopy(planning_problem)
continue ##break
if count == len(permutation):
print(f"\nSUCCESSFUL PARTIAL PLAN ORDERING: {permutation}") ## Bill's hack
return list(permutation), temp
print(f"NO SUCCESSFUL PARTIAL PLAN: {level}") ## Bill's hack
return None, planning_problem ## added planning_problem... its gotta return a planning problem and start over if it fails, but maybe this is saying return fail and the unsolved planning problem

def execute(self):
"""Finds total-order solution for a planning graph"""

graphPlan_solution = GraphPlan(self.planning_problem).execute()

## Bill's stuff from playing around
## print(f"UNFILTERED PLAN: {graphPlan_solution}") ## Bill's hack
## pnl(graphPlan_solution)
## for possible_plan in graphPlan_solution:
## possible_plan = [possible_plan]
## filtered_possible_plan = self.filter(possible_plan)
## print(f"POSSIBLE PLAN: {filtered_possible_plan}") ## Bill's hack
## flattened_graphplan = self.filter(graphPlan_solution)
## flattened_graphplan = sum(graphPlan_solution, []) ## Bill's hack
## flattened_graphplan = sum(flattened_graphplan, []) ## Bill's hack
## flattened_graphplan = [flattened_graphplan]
## graphPlan_solution = [flattened_graphplan] ## Bill's hack
## pnl(flattened_graphplan)

## I think I have to go over all permutations of possbile partial graphplans

for possible_plan in itertools.permutations(graphPlan_solution): ## Bill's hack

## possible_plan = [possible_plan] ## Bill's hack, stuff below expect a list with one element which is also a list
## filtered_solution = self.filter(graphPlan_solution) # original

filtered_solution = self.filter(possible_plan) # my mod

print(f"TRYING FILTERED PLAN: {filtered_solution}") ## Bill's hack

## filtered_solution = self.filter(possible_plan) # mod
## print(f"\nFILTERED PLAN: {filtered_solution}") ## Bill's hack
## pnl(filtered_solution)
## filtered_solution = possible_plan

ordered_solution = []
planning_problem = self.planning_problem
for level in filtered_solution:

## print(f"TRYING SOLUTION LEVEL: {level}") ## Bill's hack

## the below is a key line, the key line
level_solution, planning_problem = self.orderlevel(level, planning_problem) ## actions get applied
if not level_solution: # This checks if level_solution is None or an empty list
print(f"PLAN FAIL: {filtered_solution}") ## Bill's hack
continue ## Bill's hack!! if empty, continue looking.

print(f"LEVEL SOLUTION: {level_solution}") ## Bill's hack
##print(f"CURRENT STATE: {planning_problem.initial}\n") ## Bill's hack
## for action in level_solution:
## print(f"APPLY ACTION: {action}") ## Bill's hack
## planning_problem.act(action) # complete guess, apply action to the problem and keep going

## I think we need to apply the plan to the planning problem and modify it
for element in level_solution:
ordered_solution.append(element)

if not ordered_solution:
continue ## no plan possible from the partial plan at the level
else:
print(f"WORKING SOL'N: {ordered_solution}") ## Bill's hack
break

return ordered_solution

46 changes: 46 additions & 0 deletions logistics-test-probs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


## initial_state = 'In(C1, R1) & In(C2, D1) & In(C3, D2) & In(R1, D1) & Holding(R1)'

logisticsPlan('In(C1, D1)')

logisticsPlan('In(C1,D2)')

logisticsPlan('In(C1, D1) & In(R1, D2)')
logisticsPlan('In(R1, D2) & In(C1, D1)')

logisticsPlan('In(C1, D1) & In(C3, R1)')
logisticsPlan('In(C1, D1) & In(C3, R1) & In(R1, D3)')

logisticsPlan('In(C1, D1) & In(R1, D3) & In(C3, R1)')
logisticsPlan('In(C1, D1) & In(C3, D3)')

logisticsPlan('In(C1, D1) & In(R1, D2) & In(C3, R1)')

logisticsPlan('In(C1, D1) & In(C3, R1) & In(R1, D3)')

logisticsPlan('In(C1, D1) & In(C2, D3)')


logisticsPlan('In(C3, D1)')

logisticsPlan('In(C2, D3)')

logisticsPlan('In(C3, D3)')


#no plans for these below
logisticsPlan('In(C2, D3) & In(C3, D3)')

logisticsPlan('In(C3, D3) & In(C2, D3)')

logisticsPlan('In(C1, D2) & In(C3, D3)')

logisticsPlan('In(C1, D3) & In(C2, D3) & In(C3, D3)') ## homework??

logisticsPlan('In(C1, D2) & In(C3, D3) & In(C2, D1)')


#kaboom... didn't stop?
logisticsPlan('In(C1, D2) & In(C3, D3) & In(C2, D3) & In(R1, D1)')

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions other_shit_idgafabout/aima_8puzzle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Demo for A* with EightPuzzle
For use with the AIMA codebase: https://github.com/aimacode/aima-python
CMSC 421 - Fall 2025
"""
from time import time
from search import EightPuzzle, astar_search

# INITIAL_STATE = (1, 2, 3, 4, 5, 6, 7, 8, 0) # already solved
INITIAL_STATE = (1, 2, 3, 4, 5, 6, 7, 0, 8) # just one swap to solve
# INITIAL_STATE = (1, 2, 3, 4, 0, 6, 7, 5, 8) # just two swaps to solve
# INITIAL_STATE = (1, 2, 3, 0, 4, 6, 7, 5, 8) # just three swaps to solve
# INITIAL_STATE = (8, 3, 2, 4, 5, 7, 1, 6, 0) # more complex initial state

EP = EightPuzzle(INITIAL_STATE)
print('Initial State: ' + str(INITIAL_STATE))
print('Initial State solvable: ' + str(EP.check_solvability(INITIAL_STATE)))
print('Running A*...')
t0 = time()
astar_search(EP, display=True)
print('Solved in %f seconds'%(time()-t0))
93 changes: 93 additions & 0 deletions other_shit_idgafabout/aima_my_tsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""
Code skeleton for A* with TSP
For use with the AIMA codebase: https://github.com/aimacode/aima-python
CMSC 421 - Fall 2025
"""
from time import time
import numpy as np
from search import Problem, astar_search
from scipy.sparse import csgraph

### Define TSP ###

class MyTSP(Problem):

# NOTE: This is just a suggestion for setting up your __init__,
# you can use any design you want
def __init__(self, weights, initial=(0,), goal=None):
super().__init__(initial, goal)
self.weights = weights
self.num_cities = weights.shape[0]
self.cities = list(range(0, self.num_cities))

def actions(self, state):
"""Return the actions that can be executed in the given
state. The result would typically be a list, but if there are
many actions, consider yielding them one at a time in an
iterator, rather than building them all at once."""
raise NotImplementedError
# TODO: your code here

# NOTE: If you make your state a list object, you'll wind
# up with an error like this: TypeError: unhashable type: 'list'
# One work-around is the make your states tuples instead.
def result(self, state, action):
"""Return the state that results from executing the given
action in the given state. The action must be one of
self.actions(state)."""
raise NotImplementedError
# TODO: your code here

def goal_test(self, state):
"""Return True if the state is a goal. The default method compares the
state to self.goal or checks for state in self.goal if it is a
list, as specified in the constructor. Override this method if
checking against a single self.goal is not enough."""
raise NotImplementedError
# TODO: your code here

# NOTE: Remember the full cost includes the round trip back to the starting city!
# So if you are adding the final city to the path, you should also add the cost
# for the final edge too.
def path_cost(self, c, state1, action, state2):
"""Return the cost of a solution path that arrives at state2 from
state1 via action, assuming cost c to get up to state1. If the problem
is such that the path doesn't matter, this function will only look at
state2. If the path does matter, it will consider c and maybe state1
and action. The default method costs 1 for every step in the path."""
raise NotImplementedError
# TODO: your code here

def value(self, state):
"""For optimization problems, each state has a value. Hill Climbing
and related algorithms try to maximize this value."""
raise NotImplementedError
# TODO: your code here

# NOTE: For debugging purposes, you can use h(n)=0 while writing and testing
# the rest of your code
def h(self, node):
"""Return the heuristic value for a given state. astar_search will
look for this heuristic function when run."""
raise NotImplementedError
# TODO: your code here

### Run A* ###

# NOTE: select a weight matrix to load, depending on where you unzipped them
MATRIX_FILE = '/home/carwyn/dev/phd/ta/aima/aima-python/aima-data/mats_911/5_random_adj_mat_0.txt'

MAT = np.loadtxt(MATRIX_FILE)
print('Loaded road cost matrix:')
print(MAT)
MTSP = MyTSP(MAT)

print('Running A*...')
t0 = time()
tsp_sol = astar_search(MTSP, display=True)
print('Solved in %f seconds'%(time()-t0))

tsp_sol = tsp_sol.state
print('Solution Path: ' + str(tsp_sol))
sol_cost = MTSP.value(tsp_sol)
print('Solution Cost: ' + str(sol_cost))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading