Thanks to visit codestin.com
Credit goes to github.com

Skip to content

removed inf and isclose definition from utils and replaced with np.inf and np.isclose #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 183 commits into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
fe514c6
changed queue to set in AC3
dmeoli Mar 24, 2019
0129aa9
re-added test commented by mistake
dmeoli Mar 28, 2019
03551fb
added the mentioned AC4 algorithm for constraint propagation
dmeoli Apr 11, 2019
c0b8383
Merge branch 'master' into master
dmeoli Apr 11, 2019
6986247
added doctest in Sudoku for AC4 and and the possibility of choosing t…
dmeoli Apr 11, 2019
b3cd24c
removed useless doctest for AC4 in Sudoku because AC4's tests are alr…
dmeoli Apr 11, 2019
9e0fa55
added map coloring SAT problems
dmeoli Jun 17, 2019
f743146
fixed typo errors and removed unnecessary brackets
dmeoli Jun 17, 2019
20ab0e5
reformulated the map coloring problem
dmeoli Jul 4, 2019
404b179
Revert "reformulated the map coloring problem"
dmeoli Jul 4, 2019
c9c5106
Revert "fixed typo errors and removed unnecessary brackets"
dmeoli Jul 4, 2019
3243ba1
Revert "added map coloring SAT problems"
dmeoli Jul 4, 2019
2af1659
Revert "removed useless doctest for AC4 in Sudoku because AC4's tests…
dmeoli Jul 4, 2019
0c7e5af
Revert "added doctest in Sudoku for AC4 and and the possibility of ch…
dmeoli Jul 4, 2019
ff8c411
Revert "added the mentioned AC4 algorithm for constraint propagation"
dmeoli Jul 4, 2019
93af259
added map coloring SAT problem
dmeoli Jul 4, 2019
002a34e
Merge remote-tracking branch 'upstream/master'
dmeoli Jul 4, 2019
6641c2c
fixed build error
dmeoli Jul 4, 2019
9399dfc
Revert "added map coloring SAT problem"
dmeoli Jul 29, 2019
e130909
Revert "fixed build error"
dmeoli Jul 29, 2019
78bdeb1
Merge remote-tracking branch 'upstream/master'
dmeoli Jul 29, 2019
2f62776
added map coloring SAT problem
dmeoli Jul 29, 2019
aaea704
removed redundant parentheses
dmeoli Jul 29, 2019
0cd6386
Merge remote-tracking branch 'upstream/master'
dmeoli Aug 7, 2019
be656aa
added Viterbi algorithm
dmeoli Aug 14, 2019
c74933a
added monkey & bananas planning problem
dmeoli Aug 23, 2019
6d229ce
simplified condition in search.py
dmeoli Aug 23, 2019
24041e9
added tests for monkey & bananas planning problem
dmeoli Aug 23, 2019
9d37ae0
removed monkey & bananas planning problem
dmeoli Aug 23, 2019
459aae6
Revert "removed monkey & bananas planning problem"
dmeoli Aug 23, 2019
dbfb9c1
Revert "added tests for monkey & bananas planning problem"
dmeoli Aug 23, 2019
14d9014
Revert "simplified condition in search.py"
dmeoli Aug 23, 2019
5eb29cd
Revert "added monkey & bananas planning problem"
dmeoli Aug 23, 2019
396c38b
Merge remote-tracking branch 'upstream/master'
dmeoli Aug 23, 2019
776c131
defined the PlanningProblem as a specialization of a search.Problem &…
dmeoli Aug 27, 2019
ccc7de1
fixed doctest in logic.py
dmeoli Aug 27, 2019
7e98afb
fixed doctest for cascade_distribution
dmeoli Aug 27, 2019
061cba1
added ForwardPlanner and tests
dmeoli Aug 30, 2019
8c10d9f
added __lt__ implementation for Expr
dmeoli Aug 30, 2019
aa61869
added more tests
dmeoli Aug 30, 2019
c4139e5
renamed forward planner
dmeoli Aug 31, 2019
e4c4343
Revert "renamed forward planner"
dmeoli Aug 31, 2019
6e084c0
renamed forward planner class & added doc
dmeoli Aug 31, 2019
b6a0cbd
added backward planner and tests
dmeoli Sep 2, 2019
1131f4d
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 3, 2019
1af8978
fixed mdp4e.py doctests
dmeoli Sep 3, 2019
a4ad133
removed ignore_delete_lists_heuristic flag
dmeoli Sep 3, 2019
26f2b5d
fixed heuristic for forward and backward planners
dmeoli Sep 6, 2019
9faf17a
added SATPlan and tests
dmeoli Sep 6, 2019
0be0f5d
fixed ignore delete lists heuristic in forward and backward planners
dmeoli Sep 7, 2019
2cc2d3f
fixed backward planner and added tests
dmeoli Sep 8, 2019
4222176
updated doc
dmeoli Sep 8, 2019
30af352
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 11, 2019
b69a907
added nary csp definition and examples
dmeoli Sep 11, 2019
6ff465a
added CSPlan and tests
dmeoli Sep 11, 2019
d3c291c
fixed CSPlan
dmeoli Sep 11, 2019
785850a
added book's cryptarithmetic puzzle example
dmeoli Sep 11, 2019
7249058
fixed typo errors in test_csp
dmeoli Sep 11, 2019
42e9cbc
fixed #1111
dmeoli Sep 12, 2019
0fb48f6
added sortedcontainers to yml and doc to CSPlan
dmeoli Sep 12, 2019
5cce7d9
added tests for n-ary csp
dmeoli Sep 13, 2019
b567a6d
fixed utils.extend
dmeoli Sep 13, 2019
2eba772
updated test_probability.py
dmeoli Sep 14, 2019
427e85a
converted static methods to functions
dmeoli Sep 15, 2019
cd1ad41
added AC3b and AC4 with heuristic and tests
dmeoli Sep 15, 2019
0092f27
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 16, 2019
d9dd4bb
added conflict-driven clause learning sat solver
dmeoli Sep 16, 2019
c0220d2
added tests for cdcl and heuristics
dmeoli Sep 16, 2019
8f0779d
fixed probability.py
dmeoli Sep 17, 2019
7a59010
fixed import
dmeoli Sep 17, 2019
0135db6
fixed kakuro
dmeoli Sep 20, 2019
ac98bd8
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 21, 2019
dca70da
added Martelli and Montanari rule-based unification algorithm
dmeoli Sep 25, 2019
84e7a55
removed duplicate standardize_variables
dmeoli Sep 25, 2019
20bc37b
renamed variables known as built-in functions
dmeoli Sep 26, 2019
4b02d92
fixed typos in learning.py
dmeoli Sep 26, 2019
8427b5f
renamed some files and fixed typos
dmeoli Sep 26, 2019
3ffe3e9
fixed typos
dmeoli Sep 26, 2019
2d0dbc2
fixed typos
dmeoli Sep 27, 2019
b7e8206
fixed tests
dmeoli Sep 27, 2019
0c5f0ac
removed unify_mm
dmeoli Sep 29, 2019
bcc169d
remove unnecessary brackets
dmeoli Sep 29, 2019
9dd097b
fixed tests
dmeoli Sep 29, 2019
abc8f17
moved utility functions to utils.py
dmeoli Sep 29, 2019
9839d14
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 29, 2019
50e036f
fixed typos
dmeoli Oct 1, 2019
44e1f9c
moved utils function to utils.py, separated probability learning clas…
dmeoli Oct 3, 2019
17285cc
added missing learners
dmeoli Oct 3, 2019
d80fed5
fixed Travis build
dmeoli Oct 3, 2019
a734d46
fixed typos
dmeoli Oct 3, 2019
df16744
fixed typos
dmeoli Oct 3, 2019
c81425f
fixed typos
dmeoli Oct 3, 2019
0071746
fixed typos
dmeoli Oct 4, 2019
25ac7b3
Merge branch 'master' into master
dmeoli Oct 4, 2019
f4f8663
fixed typos in agents files
dmeoli Oct 4, 2019
dd8ae31
fixed imports in agent files
dmeoli Oct 4, 2019
13000ac
Merge branch 'ml'
dmeoli Oct 4, 2019
b11adf4
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 7, 2019
e041479
fixed deep learning .ipynb imports
dmeoli Oct 8, 2019
be7c131
fixed typos
dmeoli Oct 8, 2019
9b3c8ba
added SVM
dmeoli Oct 8, 2019
8bede28
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 8, 2019
fa6676c
Merge branch 'master' into ml
dmeoli Oct 8, 2019
e0b4a1c
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 24, 2019
e31a5a3
Merge branch 'master' into ml
dmeoli Oct 24, 2019
99c1b4c
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 29, 2019
a672234
Merge branch 'master' into ml
dmeoli Oct 29, 2019
b9236db
added .ipynb and fixed typos
dmeoli Nov 1, 2019
3001803
adapted code for .ipynb
dmeoli Nov 1, 2019
e5f75f3
fixed typos
dmeoli Nov 1, 2019
278574d
updated .ipynb
dmeoli Nov 1, 2019
25c590d
updated .ipynb
dmeoli Nov 1, 2019
23e3d95
updated logic.py
dmeoli Nov 1, 2019
aa79be3
updated .ipynb
dmeoli Nov 1, 2019
42a6d4a
updated .ipynb
dmeoli Nov 1, 2019
ce3d0c6
updated planning.py
dmeoli Nov 1, 2019
8f5ef83
updated inf definition
dmeoli Nov 1, 2019
9d27673
fixed typos
dmeoli Nov 2, 2019
181d257
fixed typos
dmeoli Nov 2, 2019
08ad660
fixed typos
dmeoli Nov 2, 2019
658309d
fixed typos
dmeoli Nov 2, 2019
35fc24d
Revert "fixed typos"
dmeoli Nov 2, 2019
ecc7c2d
Revert "fixed typos"
dmeoli Nov 2, 2019
dbbe897
fixed typos
dmeoli Nov 2, 2019
8ef5e0c
fixed typos
dmeoli Nov 2, 2019
cf95e44
fixed typos
dmeoli Nov 2, 2019
0d64274
fixed typos
dmeoli Nov 2, 2019
3404deb
Merge branch 'master' into ml
dmeoli Nov 2, 2019
29644d4
fixed typos and utils imports in *4e.py files
dmeoli Nov 2, 2019
43f09c6
Merge branch 'master' into ml
dmeoli Nov 2, 2019
1c68b8a
Merge remote-tracking branch 'upstream/master'
dmeoli Nov 3, 2019
47df065
Merge remote-tracking branch 'upstream/master' into ml
dmeoli Nov 3, 2019
1654a9c
fixed typos
dmeoli Nov 3, 2019
fe5801e
Merge branch 'master' into ml
dmeoli Nov 3, 2019
b3d0352
Merge remote-tracking branch 'upstream/master'
dmeoli Nov 4, 2019
3960568
Merge branch 'master' into ml
dmeoli Nov 4, 2019
089d4b9
fixed typos
dmeoli Nov 4, 2019
c531100
Merge branch 'master' into ml
dmeoli Nov 4, 2019
b065c3f
fixed typos
dmeoli Nov 6, 2019
c7787cf
fixed typos
dmeoli Nov 6, 2019
e3b6a0c
Merge branch 'master' into ml
dmeoli Nov 6, 2019
d10fa04
fixed import
dmeoli Nov 10, 2019
e334940
fixed typos
dmeoli Nov 11, 2019
598a4ca
fixed typos
dmeoli Nov 11, 2019
8aeccda
fixd typos
dmeoli Nov 11, 2019
5afbf72
fixed typos
dmeoli Nov 11, 2019
182c588
fixed typos
dmeoli Nov 14, 2019
a47a516
updated SVM
dmeoli Nov 15, 2019
45cceab
added svm test
dmeoli Nov 15, 2019
86f91f9
fixed SVM and tests
dmeoli Nov 18, 2019
3f8f759
fixed some definitions and typos
dmeoli Nov 19, 2019
602627e
fixed svm and tests
dmeoli Nov 19, 2019
47c559e
added SVMs also in learning4e.py
dmeoli Nov 19, 2019
bcec266
fixed inf definition
dmeoli Nov 19, 2019
9a2541b
fixed .travis.yml
dmeoli Nov 19, 2019
2b55d16
fixed .travis.yml
dmeoli Nov 19, 2019
6143a07
fixed import
dmeoli Nov 19, 2019
bc4dd41
fixed inf definition
dmeoli Nov 19, 2019
d6f5024
replaced cvxopt with qpsolvers
dmeoli Nov 20, 2019
3473fc6
replaced cvxopt with quadprog
dmeoli Nov 20, 2019
924a4fb
fixed some definitions
dmeoli Nov 20, 2019
0044cbf
fixed typos and removed unnecessary tests
dmeoli Nov 20, 2019
75b8c2f
replaced quadprog with qpsolvers
dmeoli Nov 20, 2019
0a5fa77
fixed extend in utils
dmeoli Nov 20, 2019
132bf13
specified error type in try-catch block
dmeoli Nov 20, 2019
b81a7a6
fixed extend in utils
dmeoli Nov 20, 2019
72b5c20
fixed typos
dmeoli Nov 21, 2019
b63a622
fixed learning.py
dmeoli Nov 21, 2019
210c800
fixed doctest errors
dmeoli Nov 21, 2019
dca1c90
added comments
dmeoli Nov 21, 2019
bc4b18f
removed unnecessary if condition
dmeoli Nov 21, 2019
bd74894
updated learning.py
dmeoli Nov 22, 2019
94e81e1
fixed imports
dmeoli Nov 24, 2019
27dd36a
removed unnecessary imports
dmeoli Nov 24, 2019
8f5b1b0
fixed keras imports
dmeoli Nov 24, 2019
ede8658
fixed typos
dmeoli Nov 24, 2019
72a9040
fixed learning_curve
dmeoli Nov 30, 2019
c8a507c
added comments
dmeoli Dec 2, 2019
1b0d37c
Merge remote-tracking branch 'upstream/master'
dmeoli Dec 3, 2019
3260123
Merge remote-tracking branch 'upstream/master'
dmeoli Dec 12, 2019
83d84d7
fixed typos
dmeoli Dec 12, 2019
6b278c3
removed inf and isclose definition from utils and replaced with numpy…
dmeoli Dec 14, 2019
2847f54
fixed doctests
dmeoli Dec 14, 2019
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
3 changes: 1 addition & 2 deletions agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ def list_things_at(self, location, tclass=Thing):
return [thing for thing in self.things
if thing.location == location and isinstance(thing, tclass)]
return [thing for thing in self.things
if all(x==y for x,y in zip(thing.location, location))
and isinstance(thing, tclass)]
if all(x == y for x, y in zip(thing.location, location)) and isinstance(thing, tclass)]

def some_things_at(self, location, tclass=Thing):
"""Return true if at least one of the things at location
Expand Down
3 changes: 1 addition & 2 deletions agents4e.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ def list_things_at(self, location, tclass=Thing):
return [thing for thing in self.things
if thing.location == location and isinstance(thing, tclass)]
return [thing for thing in self.things
if all(x==y for x,y in zip(thing.location, location))
and isinstance(thing, tclass)]
if all(x == y for x, y in zip(thing.location, location)) and isinstance(thing, tclass)]

def some_things_at(self, location, tclass=Thing):
"""Return true if at least one of the things at location
Expand Down
6 changes: 3 additions & 3 deletions deep_learning4e.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Deep learning. (Chapters 20)"""

import math
import random
import statistics

import numpy as np
from keras import Sequential, optimizers
from keras.layers import Embedding, SimpleRNN, Dense
from keras.preprocessing import sequence
Expand Down Expand Up @@ -249,7 +249,7 @@ def adam(dataset, net, loss, epochs=1000, rho=(0.9, 0.999), delta=1 / 10 ** 8,
r_hat = scalar_vector_product(1 / (1 - rho[1] ** t), r)

# rescale r_hat
r_hat = map_vector(lambda x: 1 / (math.sqrt(x) + delta), r_hat)
r_hat = map_vector(lambda x: 1 / (np.sqrt(x) + delta), r_hat)

# delta weights
delta_theta = scalar_vector_product(-l_rate, element_wise_product(s_hat, r_hat))
Expand Down Expand Up @@ -341,7 +341,7 @@ def forward(self, inputs):
res = []
# get normalized value of each input
for i in range(len(self.nodes)):
val = [(inputs[i] - mu) * self.weights[0] / math.sqrt(self.epsilon + stderr ** 2) + self.weights[1]]
val = [(inputs[i] - mu) * self.weights[0] / np.sqrt(self.epsilon + stderr ** 2) + self.weights[1]]
res.append(val)
self.nodes[i].val = val
return res
Expand Down
30 changes: 16 additions & 14 deletions games.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Games or Adversarial Search. (Chapter 5)"""
"""Games or Adversarial Search (Chapter 5)"""

import copy
import itertools
import random
from collections import namedtuple

from utils import vector_add, inf
import numpy as np

from utils import vector_add

GameState = namedtuple('GameState', 'to_move, utility, board, moves')
StochasticGameState = namedtuple('StochasticGameState', 'to_move, utility, board, moves, chance')
Expand All @@ -24,15 +26,15 @@ def minmax_decision(state, game):
def max_value(state):
if game.terminal_test(state):
return game.utility(state, player)
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, min_value(game.result(state, a)))
return v

def min_value(state):
if game.terminal_test(state):
return game.utility(state, player)
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, max_value(game.result(state, a)))
return v
Expand All @@ -53,13 +55,13 @@ def expect_minmax(state, game):
player = game.to_move(state)

def max_value(state):
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, chance_node(state, a))
return v

def min_value(state):
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, chance_node(state, a))
return v
Expand Down Expand Up @@ -94,7 +96,7 @@ def alpha_beta_search(state, game):
def max_value(state, alpha, beta):
if game.terminal_test(state):
return game.utility(state, player)
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, min_value(game.result(state, a), alpha, beta))
if v >= beta:
Expand All @@ -105,7 +107,7 @@ def max_value(state, alpha, beta):
def min_value(state, alpha, beta):
if game.terminal_test(state):
return game.utility(state, player)
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, max_value(game.result(state, a), alpha, beta))
if v <= alpha:
Expand All @@ -114,8 +116,8 @@ def min_value(state, alpha, beta):
return v

# Body of alpha_beta_search:
best_score = -inf
beta = inf
best_score = -np.inf
beta = np.inf
best_action = None
for a in game.actions(state):
v = min_value(game.result(state, a), best_score, beta)
Expand All @@ -135,7 +137,7 @@ def alpha_beta_cutoff_search(state, game, d=4, cutoff_test=None, eval_fn=None):
def max_value(state, alpha, beta, depth):
if cutoff_test(state, depth):
return eval_fn(state)
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, min_value(game.result(state, a), alpha, beta, depth + 1))
if v >= beta:
Expand All @@ -146,7 +148,7 @@ def max_value(state, alpha, beta, depth):
def min_value(state, alpha, beta, depth):
if cutoff_test(state, depth):
return eval_fn(state)
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, max_value(game.result(state, a), alpha, beta, depth + 1))
if v <= alpha:
Expand All @@ -158,8 +160,8 @@ def min_value(state, alpha, beta, depth):
# The default test cuts off at depth d or at a terminal state
cutoff_test = (cutoff_test or (lambda state, depth: depth > d or game.terminal_test(state)))
eval_fn = eval_fn or (lambda state: game.utility(state, player))
best_score = -inf
beta = inf
best_score = -np.inf
beta = np.inf
best_action = None
for a in game.actions(state):
v = min_value(game.result(state, a), best_score, beta, 1)
Expand Down
30 changes: 16 additions & 14 deletions games4e.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Games or Adversarial Search. (Chapter 5)"""
"""Games or Adversarial Search (Chapter 5)"""

import copy
import itertools
import random
from collections import namedtuple

from utils4e import vector_add, MCT_Node, ucb, inf
import numpy as np

from utils4e import vector_add, MCT_Node, ucb

GameState = namedtuple('GameState', 'to_move, utility, board, moves')
StochasticGameState = namedtuple('StochasticGameState', 'to_move, utility, board, moves, chance')
Expand All @@ -24,15 +26,15 @@ def minmax_decision(state, game):
def max_value(state):
if game.terminal_test(state):
return game.utility(state, player)
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, min_value(game.result(state, a)))
return v

def min_value(state):
if game.terminal_test(state):
return game.utility(state, player)
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, max_value(game.result(state, a)))
return v
Expand All @@ -53,13 +55,13 @@ def expect_minmax(state, game):
player = game.to_move(state)

def max_value(state):
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, chance_node(state, a))
return v

def min_value(state):
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, chance_node(state, a))
return v
Expand Down Expand Up @@ -94,7 +96,7 @@ def alpha_beta_search(state, game):
def max_value(state, alpha, beta):
if game.terminal_test(state):
return game.utility(state, player)
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, min_value(game.result(state, a), alpha, beta))
if v >= beta:
Expand All @@ -105,7 +107,7 @@ def max_value(state, alpha, beta):
def min_value(state, alpha, beta):
if game.terminal_test(state):
return game.utility(state, player)
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, max_value(game.result(state, a), alpha, beta))
if v <= alpha:
Expand All @@ -114,8 +116,8 @@ def min_value(state, alpha, beta):
return v

# Body of alpha_beta_search:
best_score = -inf
beta = inf
best_score = -np.inf
beta = np.inf
best_action = None
for a in game.actions(state):
v = min_value(game.result(state, a), best_score, beta)
Expand All @@ -135,7 +137,7 @@ def alpha_beta_cutoff_search(state, game, d=4, cutoff_test=None, eval_fn=None):
def max_value(state, alpha, beta, depth):
if cutoff_test(state, depth):
return eval_fn(state)
v = -inf
v = -np.inf
for a in game.actions(state):
v = max(v, min_value(game.result(state, a), alpha, beta, depth + 1))
if v >= beta:
Expand All @@ -146,7 +148,7 @@ def max_value(state, alpha, beta, depth):
def min_value(state, alpha, beta, depth):
if cutoff_test(state, depth):
return eval_fn(state)
v = inf
v = np.inf
for a in game.actions(state):
v = min(v, max_value(game.result(state, a), alpha, beta, depth + 1))
if v <= alpha:
Expand All @@ -158,8 +160,8 @@ def min_value(state, alpha, beta, depth):
# The default test cuts off at depth d or at a terminal state
cutoff_test = (cutoff_test or (lambda state, depth: depth > d or game.terminal_test(state)))
eval_fn = eval_fn or (lambda state: game.utility(state, player))
best_score = -inf
beta = inf
best_score = -np.inf
beta = np.inf
best_action = None
for a in game.actions(state):
v = min_value(game.result(state, a), best_score, beta, 1)
Expand Down
30 changes: 12 additions & 18 deletions gui/romania_problem.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from copy import deepcopy
from tkinter import *
import sys
import os.path
import math
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from search import *
from search import breadth_first_tree_search as bfts, depth_first_tree_search as dfts, \
depth_first_graph_search as dfgs, breadth_first_graph_search as bfs, uniform_cost_search as ucs, \
astar_search as asts
from utils import PriorityQueue
from copy import deepcopy

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

root = None
city_coord = {}
Expand Down Expand Up @@ -289,7 +285,6 @@ def make_rectangle(map, x0, y0, margin, city_name):


def make_legend(map):

rect1 = map.create_rectangle(600, 100, 610, 110, fill="white")
text1 = map.create_text(615, 105, anchor=W, text="Un-explored")

Expand Down Expand Up @@ -325,13 +320,11 @@ def tree_search(problem):
display_current(node)
if counter % 3 == 1 and counter >= 0:
if problem.goal_test(node.state):

return node
frontier.extend(node.expand(problem))

display_frontier(frontier)
if counter % 3 == 2 and counter >= 0:

display_explored(node)
return None

Expand Down Expand Up @@ -562,7 +555,7 @@ def astar_search(problem, h=None):

# TODO:
# Remove redundant code.
# Make the interchangbility work between various algorithms at each step.
# Make the interchangeability work between various algorithms at each step.
def on_click():
"""
This function defines the action of the 'Next' button.
Expand All @@ -572,47 +565,47 @@ def on_click():
if "Breadth-First Tree Search" == algo.get():
node = breadth_first_tree_search(romania_problem)
if node is not None:
final_path = bfts(romania_problem).solution()
final_path = breadth_first_tree_search(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
counter += 1
elif "Depth-First Tree Search" == algo.get():
node = depth_first_tree_search(romania_problem)
if node is not None:
final_path = dfts(romania_problem).solution()
final_path = depth_first_tree_search(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
counter += 1
elif "Breadth-First Graph Search" == algo.get():
node = breadth_first_graph_search(romania_problem)
if node is not None:
final_path = bfs(romania_problem).solution()
final_path = breadth_first_graph_search(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
counter += 1
elif "Depth-First Graph Search" == algo.get():
node = depth_first_graph_search(romania_problem)
if node is not None:
final_path = dfgs(romania_problem).solution()
final_path = depth_first_graph_search(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
counter += 1
elif "Uniform Cost Search" == algo.get():
node = uniform_cost_search(romania_problem)
if node is not None:
final_path = ucs(romania_problem).solution()
final_path = uniform_cost_search(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
counter += 1
elif "A* - Search" == algo.get():
node = astar_search(romania_problem)
if node is not None:
final_path = asts(romania_problem).solution()
final_path = astar_search(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
Expand All @@ -626,6 +619,7 @@ def reset_map():
city_map.itemconfig(city_coord[city], fill="white")
next_button.config(state="normal")


# TODO: Add more search algorithms in the OptionMenu


Expand Down
Loading