Skip to content

Commit 283fa41

Browse files
dmeoliantmarakis
authored andcommitted
moved util functions to utils.py, moved probability learners from learning.py to probabilistic_learning.py with tests, fixed typos and fixed imports in .ipynb files (#1120)
* changed queue to set in AC3 Changed queue to set in AC3 (as in the pseudocode of the original algorithm) to reduce the number of consistency-check due to the redundancy of the same arcs in queue. For example, on the harder1 configuration of the Sudoku CSP the number consistency-check has been reduced from 40464 to 12562! * re-added test commented by mistake * added the mentioned AC4 algorithm for constraint propagation AC3 algorithm has non-optimal worst case time-complexity O(cd^3 ), while AC4 algorithm runs in O(cd^2) worst case time * added doctest in Sudoku for AC4 and and the possibility of choosing the constant propagation algorithm in mac inference * removed useless doctest for AC4 in Sudoku because AC4's tests are already present in test_csp.py * added map coloring SAT problems * fixed typo errors and removed unnecessary brackets * reformulated the map coloring problem * Revert "reformulated the map coloring problem" This reverts commit 20ab0e5. * Revert "fixed typo errors and removed unnecessary brackets" This reverts commit f743146. * Revert "added map coloring SAT problems" This reverts commit 9e0fa55. * Revert "removed useless doctest for AC4 in Sudoku because AC4's tests are already present in test_csp.py" This reverts commit b3cd24c. * Revert "added doctest in Sudoku for AC4 and and the possibility of choosing the constant propagation algorithm in mac inference" This reverts commit 6986247. * Revert "added the mentioned AC4 algorithm for constraint propagation" This reverts commit 03551fb. * added map coloring SAT problem * fixed build error * Revert "added map coloring SAT problem" This reverts commit 93af259. * Revert "fixed build error" This reverts commit 6641c2c. * added map coloring SAT problem * removed redundant parentheses * added Viterbi algorithm * added monkey & bananas planning problem * simplified condition in search.py * added tests for monkey & bananas planning problem * removed monkey & bananas planning problem * Revert "removed monkey & bananas planning problem" This reverts commit 9d37ae0. * Revert "added tests for monkey & bananas planning problem" This reverts commit 24041e9. * Revert "simplified condition in search.py" This reverts commit 6d229ce. * Revert "added monkey & bananas planning problem" This reverts commit c74933a. * defined the PlanningProblem as a specialization of a search.Problem & fixed typo errors * fixed doctest in logic.py * fixed doctest for cascade_distribution * added ForwardPlanner and tests * added __lt__ implementation for Expr * added more tests * renamed forward planner * Revert "renamed forward planner" This reverts commit c4139e5. * renamed forward planner class & added doc * added backward planner and tests * fixed mdp4e.py doctests * removed ignore_delete_lists_heuristic flag * fixed heuristic for forward and backward planners * added SATPlan and tests * fixed ignore delete lists heuristic in forward and backward planners * fixed backward planner and added tests * updated doc * added nary csp definition and examples * added CSPlan and tests * fixed CSPlan * added book's cryptarithmetic puzzle example * fixed typo errors in test_csp * fixed #1111 * added sortedcontainers to yml and doc to CSPlan * added tests for n-ary csp * fixed utils.extend * updated test_probability.py * converted static methods to functions * added AC3b and AC4 with heuristic and tests * added conflict-driven clause learning sat solver * added tests for cdcl and heuristics * fixed probability.py * fixed import * fixed kakuro * added Martelli and Montanari rule-based unification algorithm * removed duplicate standardize_variables * renamed variables known as built-in functions * fixed typos in learning.py * renamed some files and fixed typos * fixed typos * fixed typos * fixed tests * removed unify_mm * remove unnecessary brackets * fixed tests * moved utility functions to utils.py * fixed typos * moved utils function to utils.py, separated probability learning classes from learning.py, fixed typos and fixed imports in .ipynb files * added missing learners * fixed Travis build * fixed typos * fixed typos * fixed typos * fixed typos * fixed typos in agents files * fixed imports in agent files
1 parent c910cca commit 283fa41

24 files changed

+1400
-1419
lines changed

agents.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ def run(self, steps=1000):
333333

334334
def list_things_at(self, location, tclass=Thing):
335335
"""Return all things exactly at a given location."""
336-
return [thing for thing in self.things
337-
if thing.location == location and isinstance(thing, tclass)]
336+
return [thing for thing in self.things if thing.location == location and isinstance(thing, tclass)]
338337

339338
def some_things_at(self, location, tclass=Thing):
340339
"""Return true if at least one of the things at location
@@ -993,9 +992,8 @@ def is_done(self):
993992
else:
994993
print("Death by {} [-1000].".format(explorer[0].killed_by))
995994
else:
996-
print("Explorer climbed out {}."
997-
.format(
998-
"with Gold [+1000]!" if Gold() not in self.things else "without Gold [+0]"))
995+
print("Explorer climbed out {}.".format("with Gold [+1000]!"
996+
if Gold() not in self.things else "without Gold [+0]"))
999997
return True
1000998

1001999
# TODO: Arrow needs to be implemented
@@ -1012,9 +1010,9 @@ def compare_agents(EnvFactory, AgentFactories, n=10, steps=1000):
10121010
>>> environment = TrivialVacuumEnvironment
10131011
>>> agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]
10141012
>>> result = compare_agents(environment, agents)
1015-
>>> performance_ModelBasedVacummAgent = result[0][1]
1016-
>>> performance_ReflexVacummAgent = result[1][1]
1017-
>>> performance_ReflexVacummAgent <= performance_ModelBasedVacummAgent
1013+
>>> performance_ModelBasedVacuumAgent = result[0][1]
1014+
>>> performance_ReflexVacuumAgent = result[1][1]
1015+
>>> performance_ReflexVacuumAgent <= performance_ModelBasedVacuumAgent
10181016
True
10191017
"""
10201018
envs = [EnvFactory() for i in range(n)]

agents4e.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,9 @@ def compare_agents(EnvFactory, AgentFactories, n=10, steps=1000):
10121012
>>> environment = TrivialVacuumEnvironment
10131013
>>> agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]
10141014
>>> result = compare_agents(environment, agents)
1015-
>>> performance_ModelBasedVacummAgent = result[0][1]
1016-
>>> performance_ReflexVacummAgent = result[1][1]
1017-
>>> performance_ReflexVacummAgent <= performance_ModelBasedVacummAgent
1015+
>>> performance_ModelBasedVacuumAgent = result[0][1]
1016+
>>> performance_ReflexVacuumAgent = result[1][1]
1017+
>>> performance_ReflexVacuumAgent <= performance_ModelBasedVacuumAgent
10181018
True
10191019
"""
10201020
envs = [EnvFactory() for i in range(n)]

csp.ipynb

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"outputs": [],
1717
"source": [
1818
"from csp import *\n",
19-
"from notebook import psource, pseudocode, plot_NQueens\n",
19+
"from notebook import psource, plot_NQueens\n",
2020
"%matplotlib inline\n",
2121
"\n",
2222
"# Hide warnings in the matplotlib sections\n",
@@ -3068,8 +3068,17 @@
30683068
"nbconvert_exporter": "python",
30693069
"pygments_lexer": "ipython3",
30703070
"version": "3.6.8"
3071+
},
3072+
"pycharm": {
3073+
"stem_cell": {
3074+
"cell_type": "raw",
3075+
"source": [],
3076+
"metadata": {
3077+
"collapsed": false
3078+
}
3079+
}
30713080
}
30723081
},
30733082
"nbformat": 4,
30743083
"nbformat_minor": 1
3075-
}
3084+
}

0 commit comments

Comments
 (0)