Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.83 KB | None | 0 0
  1. # Python modul vo koj se implementirani algoritmite za informirano prebaruvanje
  2.  
  3. # ______________________________________________________________________________________________
  4. # Improtiranje na dopolnitelno potrebni paketi za funkcioniranje na kodovite
  5.  
  6. import sys
  7. import bisect
  8.  
  9. infinity = float('inf') # sistemski definirana vrednost za beskonecnost
  10.  
  11.  
  12. # ______________________________________________________________________________________________
  13. # Definiranje na pomosni strukturi za cuvanje na listata na generirani, no neprovereni jazli
  14.  
  15. class Queue:
  16. """Queue is an abstract class/interface. There are three types:
  17. Stack(): A Last In First Out Queue.
  18. FIFOQueue(): A First In First Out Queue.
  19. PriorityQueue(order, f): Queue in sorted order (default min-first).
  20. Each type supports the following methods and functions:
  21. q.append(item) -- add an item to the queue
  22. q.extend(items) -- equivalent to: for item in items: q.append(item)
  23. q.pop() -- return the top item from the queue
  24. len(q) -- number of items in q (also q.__len())
  25. item in q -- does q contain item?
  26. Note that isinstance(Stack(), Queue) is false, because we implement stacks
  27. as lists. If Python ever gets interfaces, Queue will be an interface."""
  28.  
  29. def __init__(self):
  30. raise NotImplementedError
  31.  
  32. def extend(self, items):
  33. for item in items:
  34. self.append(item)
  35.  
  36.  
  37. def Stack():
  38. """A Last-In-First-Out Queue."""
  39. return []
  40.  
  41.  
  42. class FIFOQueue(Queue):
  43. """A First-In-First-Out Queue."""
  44.  
  45. def __init__(self):
  46. self.A = []
  47. self.start = 0
  48.  
  49. def append(self, item):
  50. self.A.append(item)
  51.  
  52. def __len__(self):
  53. return len(self.A) - self.start
  54.  
  55. def extend(self, items):
  56. self.A.extend(items)
  57.  
  58. def pop(self):
  59. e = self.A[self.start]
  60. self.start += 1
  61. if self.start > 5 and self.start > len(self.A) / 2:
  62. self.A = self.A[self.start:]
  63. self.start = 0
  64. return e
  65.  
  66. def __contains__(self, item):
  67. return item in self.A[self.start:]
  68.  
  69.  
  70. class PriorityQueue(Queue):
  71. """A queue in which the minimum (or maximum) element (as determined by f and
  72. order) is returned first. If order is min, the item with minimum f(x) is
  73. returned first; if order is max, then it is the item with maximum f(x).
  74. Also supports dict-like lookup. This structure will be most useful in informed searches"""
  75.  
  76. def __init__(self, order=min, f=lambda x: x):
  77. self.A = []
  78. self.order = order
  79. self.f = f
  80.  
  81. def append(self, item):
  82. bisect.insort(self.A, (self.f(item), item))
  83.  
  84. def __len__(self):
  85. return len(self.A)
  86.  
  87. def pop(self):
  88. if self.order == min:
  89. return self.A.pop(0)[1]
  90. else:
  91. return self.A.pop()[1]
  92.  
  93. def __contains__(self, item):
  94. return any(item == pair[1] for pair in self.A)
  95.  
  96. def __getitem__(self, key):
  97. for _, item in self.A:
  98. if item == key:
  99. return item
  100.  
  101. def __delitem__(self, key):
  102. for i, (value, item) in enumerate(self.A):
  103. if item == key:
  104. self.A.pop(i)
  105.  
  106.  
  107. # ______________________________________________________________________________________________
  108. # Definiranje na klasa za strukturata na problemot koj ke go resavame so prebaruvanje
  109. # Klasata Problem e apstraktna klasa od koja pravime nasleduvanje za definiranje na osnovnite karakteristiki
  110. # na sekoj eden problem sto sakame da go resime
  111.  
  112.  
  113. class Problem:
  114. """The abstract class for a formal problem. You should subclass this and
  115. implement the method successor, and possibly __init__, goal_test, and
  116. path_cost. Then you will create instances of your subclass and solve them
  117. with the various search functions."""
  118.  
  119. def __init__(self, initial, goal=None):
  120. """The constructor specifies the initial state, and possibly a goal
  121. state, if there is a unique goal. Your subclass's constructor can add
  122. other arguments."""
  123. self.initial = initial
  124. self.goal = goal
  125.  
  126. def successor(self, state):
  127. """Given a state, return a dictionary of {action : state} pairs reachable
  128. from this state. If there are many successors, consider an iterator
  129. that yields the successors one at a time, rather than building them
  130. all at once. Iterators will work fine within the framework. Yielding is not supported in Python 2.7"""
  131. raise NotImplementedError
  132.  
  133. def actions(self, state):
  134. """Given a state, return a list of all actions possible from that state"""
  135. raise NotImplementedError
  136.  
  137. def result(self, state, action):
  138. """Given a state and action, return the resulting state"""
  139. raise NotImplementedError
  140.  
  141. def goal_test(self, state):
  142. """Return True if the state is a goal. The default method compares the
  143. state to self.goal, as specified in the constructor. Implement this
  144. method if checking against a single self.goal is not enough."""
  145. return state == self.goal
  146.  
  147. def path_cost(self, c, state1, action, state2):
  148. """Return the cost of a solution path that arrives at state2 from
  149. state1 via action, assuming cost c to get up to state1. If the problem
  150. is such that the path doesn't matter, this function will only look at
  151. state2. If the path does matter, it will consider c and maybe state1
  152. and action. The default method costs 1 for every step in the path."""
  153. return c + 1
  154.  
  155. def value(self):
  156. """For optimization problems, each state has a value. Hill-climbing
  157. and related algorithms try to maximize this value."""
  158. raise NotImplementedError
  159.  
  160.  
  161. # ______________________________________________________________________________
  162. # Definiranje na klasa za strukturata na jazel od prebaruvanje
  163. # Klasata Node ne se nasleduva
  164.  
  165. class Node:
  166. """A node in a search tree. Contains a pointer to the parent (the node
  167. that this is a successor of) and to the actual state for this node. Note
  168. that if a state is arrived at by two paths, then there are two nodes with
  169. the same state. Also includes the action that got us to this state, and
  170. the total path_cost (also known as g) to reach the node. Other functions
  171. may add an f and h value; see best_first_graph_search and astar_search for
  172. an explanation of how the f and h values are handled. You will not need to
  173. subclass this class."""
  174.  
  175. def __init__(self, state, parent=None, action=None, path_cost=0):
  176. "Create a search tree Node, derived from a parent by an action."
  177. self.state = state
  178. self.parent = parent
  179. self.action = action
  180. self.path_cost = path_cost
  181. self.depth = 0
  182. if parent:
  183. self.depth = parent.depth + 1
  184.  
  185. def __repr__(self):
  186. return "<Node %s>" % (self.state,)
  187.  
  188. def __lt__(self, node):
  189. return self.state < node.state
  190.  
  191. def expand(self, problem):
  192. "List the nodes reachable in one step from this node."
  193. return [self.child_node(problem, action)
  194. for action in problem.actions(self.state)]
  195.  
  196. def child_node(self, problem, action):
  197. "Return a child node from this node"
  198. next = problem.result(self.state, action)
  199. return Node(next, self, action,
  200. problem.path_cost(self.path_cost, self.state,
  201. action, next))
  202.  
  203. def solution(self):
  204. "Return the sequence of actions to go from the root to this node."
  205. return [node.action for node in self.path()[1:]]
  206.  
  207. def solve(self):
  208. "Return the sequence of states to go from the root to this node."
  209. return [node.state for node in self.path()[0:]]
  210.  
  211. def path(self):
  212. "Return a list of nodes forming the path from the root to this node."
  213. x, result = self, []
  214. while x:
  215. result.append(x)
  216. x = x.parent
  217. return list(reversed(result))
  218.  
  219. # We want for a queue of nodes in breadth_first_search or
  220. # astar_search to have no duplicated states, so we treat nodes
  221. # with the same state as equal. [Problem: this may not be what you
  222. # want in other contexts.]
  223.  
  224. def __eq__(self, other):
  225. return isinstance(other, Node) and self.state == other.state
  226.  
  227. def __hash__(self):
  228. return hash(self.state)
  229.  
  230.  
  231. # ________________________________________________________________________________________________________
  232. # Pomosna funkcija za informirani prebaruvanja
  233. # So pomos na ovaa funkcija gi keshirame rezultatite od funkcijata na evaluacija
  234.  
  235. def memoize(fn, slot=None):
  236. """Memoize fn: make it remember the computed value for any argument list.
  237. If slot is specified, store result in that slot of first argument.
  238. If slot is false, store results in a dictionary."""
  239. if slot:
  240. def memoized_fn(obj, *args):
  241. if hasattr(obj, slot):
  242. return getattr(obj, slot)
  243. else:
  244. val = fn(obj, *args)
  245. setattr(obj, slot, val)
  246. return val
  247. else:
  248. def memoized_fn(*args):
  249. if not memoized_fn.cache.has_key(args):
  250. memoized_fn.cache[args] = fn(*args)
  251. return memoized_fn.cache[args]
  252.  
  253. memoized_fn.cache = {}
  254. return memoized_fn
  255.  
  256.  
  257. # ________________________________________________________________________________________________________
  258. # Informirano prebaruvanje vo ramki na graf
  259.  
  260. def best_first_graph_search(problem, f):
  261. """Search the nodes with the lowest f scores first.
  262. You specify the function f(node) that you want to minimize; for example,
  263. if f is a heuristic estimate to the goal, then we have greedy best
  264. first search; if f is node.depth then we have breadth-first search.
  265. There is a subtlety: the line "f = memoize(f, 'f')" means that the f
  266. values will be cached on the nodes as they are computed. So after doing
  267. a best first search you can examine the f values of the path returned."""
  268.  
  269. f = memoize(f, 'f')
  270. node = Node(problem.initial)
  271. if problem.goal_test(node.state):
  272. return node
  273. frontier = PriorityQueue(min, f)
  274. frontier.append(node)
  275. explored = set()
  276. while frontier:
  277. node = frontier.pop()
  278. if problem.goal_test(node.state):
  279. return node
  280. explored.add(node.state)
  281. for child in node.expand(problem):
  282. if child.state not in explored and child not in frontier:
  283. frontier.append(child)
  284. elif child in frontier:
  285. incumbent = frontier[child]
  286. if f(child) < f(incumbent):
  287. del frontier[incumbent]
  288. frontier.append(child)
  289. return None
  290.  
  291.  
  292. def greedy_best_first_graph_search(problem, h=None):
  293. "Greedy best-first search is accomplished by specifying f(n) = h(n)"
  294. h = memoize(h or problem.h, 'h')
  295. return best_first_graph_search(problem, h)
  296.  
  297.  
  298. def astar_search(problem, h=None):
  299. "A* search is best-first graph search with f(n) = g(n)+h(n)."
  300. h = memoize(h or problem.h, 'h')
  301. return best_first_graph_search(problem, lambda n: n.path_cost + h(n))
  302.  
  303.  
  304. # ________________________________________________________________________________________________________
  305. # Dopolnitelni prebaruvanja
  306. # Recursive_best_first_search e implementiran
  307. # Kako zadaca za studentite da gi implementiraat SMA* i IDA*
  308.  
  309. def recursive_best_first_search(problem, h=None):
  310. h = memoize(h or problem.h, 'h')
  311.  
  312. def RBFS(problem, node, flimit):
  313. if problem.goal_test(node.state):
  314. return node, 0 # (The second value is immaterial)
  315. successors = node.expand(problem)
  316. if len(successors) == 0:
  317. return None, infinity
  318. for s in successors:
  319. s.f = max(s.path_cost + h(s), node.f)
  320. while True:
  321. # Order by lowest f value
  322. successors.sort(key=lambda x: x.f)
  323. best = successors[0]
  324. if best.f > flimit:
  325. return None, best.f
  326. if len(successors) > 1:
  327. alternative = successors[1].f
  328. else:
  329. alternative = infinity
  330. result, best.f = RBFS(problem, best, min(flimit, alternative))
  331. if result is not None:
  332. return result, best.f
  333.  
  334. node = Node(problem.initial)
  335. node.f = h(node)
  336. result, bestf = RBFS(problem, node, infinity)
  337. return result
  338.  
  339.  
  340. def tree_search(problem, fringe):
  341. """Search through the successors of a problem to find a goal.
  342. The argument fringe should be an empty queue."""
  343. fringe.append(Node(problem.initial))
  344. while fringe:
  345. node = fringe.pop()
  346. print(node.state)
  347. if problem.goal_test(node.state):
  348. return node
  349. fringe.extend(node.expand(problem))
  350. return None
  351.  
  352.  
  353. def breadth_first_tree_search(problem):
  354. "Search the shallowest nodes in the search tree first."
  355. return tree_search(problem, FIFOQueue())
  356.  
  357.  
  358. def depth_first_tree_search(problem):
  359. "Search the deepest nodes in the search tree first."
  360. return tree_search(problem, Stack())
  361.  
  362.  
  363. # ________________________________________________________________________________________________________
  364. # Neinformirano prebaruvanje vo ramki na graf
  365. # Osnovnata razlika e vo toa sto ovde ne dozvoluvame jamki t.e. povtoruvanje na sostojbi
  366.  
  367. def graph_search(problem, fringe):
  368. """Search through the successors of a problem to find a goal.
  369. The argument fringe should be an empty queue.
  370. If two paths reach a state, only use the best one."""
  371. closed = {}
  372. fringe.append(Node(problem.initial))
  373. while fringe:
  374. node = fringe.pop()
  375. if problem.goal_test(node.state):
  376. return node
  377. if node.state not in closed:
  378. closed[node.state] = True
  379. fringe.extend(node.expand(problem))
  380. return None
  381.  
  382.  
  383. def breadth_first_graph_search(problem):
  384. "Search the shallowest nodes in the search tree first."
  385. return graph_search(problem, FIFOQueue())
  386.  
  387.  
  388. def depth_first_graph_search(problem):
  389. "Search the deepest nodes in the search tree first."
  390. return graph_search(problem, Stack())
  391.  
  392.  
  393. def uniform_cost_search(problem):
  394. "Search the nodes in the search tree with lowest cost first."
  395. return graph_search(problem, PriorityQueue(lambda a, b: a.path_cost < b.path_cost))
  396.  
  397.  
  398. def depth_limited_search(problem, limit=50):
  399. "depth first search with limited depth"
  400.  
  401. def recursive_dls(node, problem, limit):
  402. "helper function for depth limited"
  403. cutoff_occurred = False
  404. if problem.goal_test(node.state):
  405. return node
  406. elif node.depth == limit:
  407. return 'cutoff'
  408. else:
  409. for successor in node.expand(problem):
  410. result = recursive_dls(successor, problem, limit)
  411. if result == 'cutoff':
  412. cutoff_occurred = True
  413. elif result != None:
  414. return result
  415. if cutoff_occurred:
  416. return 'cutoff'
  417. else:
  418. return None
  419.  
  420. # Body of depth_limited_search:
  421. return recursive_dls(Node(problem.initial), problem, limit)
  422.  
  423.  
  424. Prepreki = [(1, 4), (1, 6), (1, 8), (2, 3), (2, 9), (4, 2), (4, 7), (4, 8), (5, 5), (5, 7), (6, 1), (6, 2), (6, 4),
  425. (6, 7)]
  426.  
  427.  
  428. def desnoh1(state):
  429. while (((state[0], state[1]) != (state[2], state[3])) and ((state[0], state[1]) != (state[4], state[5])) and (
  430. (state[0], state[1]) not in Prepreki)
  431. and (state[1] < 10 and state[1] > 0) and (state[0] > 0 and state[0] < 8)):
  432. Y = state[1]
  433. Y = Y + 1
  434. state = state[0], Y, state[2], state[3], state[4], state[5]
  435. newState = state[0], state[1] - 1
  436. return newState
  437.  
  438.  
  439. def levoh1(state):
  440. while (((state[0], state[1]) != (state[2], state[3])) and ((state[0], state[1]) != (state[4], state[5])) and (
  441. (state[0], state[1]) not in Prepreki)
  442. and (state[1] < 10 and state[1] > 0) and (state[0] > 0 and state[0] < 8)):
  443. Y = state[1]
  444. Y = Y - 1
  445. state = state[0], Y, state[2], state[3], state[4], state[5]
  446. newState = state[0], state[1] + 1
  447. return newState
  448.  
  449.  
  450. def goreh1(state):
  451. while (((state[0], state[1]) != (state[2], state[3])) and ((state[0], state[1]) != (state[4], state[5])) and (
  452. (state[0], state[1]) not in Prepreki)
  453. and (state[1] < 10 and state[1] > 0) and (state[0] > 0 and state[0] < 8)):
  454. X = state[0]
  455. X = X - 1
  456. state = X, state[1], state[2], state[3], state[4], state[5]
  457. newState = state[0] + 1, state[1]
  458. return newState
  459.  
  460.  
  461. def doluh1(state):
  462. while (((state[0], state[1]) != (state[2], state[3])) and ((state[0], state[1]) != (state[4], state[5])) and (
  463. (state[0], state[1]) not in Prepreki)
  464. and (state[1] < 10 and state[1] > 0) and (state[0] > 0 and state[0] < 8)):
  465. X = state[0]
  466. X = X + 1
  467. state = X, state[1], state[2], state[3], state[4], state[5]
  468. newState = state[0] - 1, state[1]
  469. return newState
  470.  
  471.  
  472. def desnoO(state):
  473. while (((state[2], state[3]) != (state[0], state[1])) and ((state[2], state[3]) != (state[4], state[5])) and (
  474. (state[2], state[3]) not in Prepreki)
  475. and (state[3] < 10 and state[3] > 0) and (state[2] > 0 and state[2] < 8)):
  476. Y = state[3]
  477. Y = Y + 1
  478. state = state[0], state[1], state[2], Y, state[4], state[5]
  479. newState = state[2], state[3] - 1
  480. return newState
  481.  
  482.  
  483. def levoO(state):
  484. while (((state[2], state[3]) != (state[0], state[1])) and ((state[2], state[3]) != (state[4], state[5])) and (
  485. (state[2], state[3]) not in Prepreki)
  486. and (state[3] < 10 and state[3] > 0) and (state[2] > 0 and state[2] < 8)):
  487. Y = state[3]
  488. Y = Y - 1
  489. state = state[0], state[1], state[2], Y, state[4], state[5]
  490. newState = state[2], state[3] + 1
  491. return newState
  492.  
  493.  
  494. def goreO(state):
  495. while (((state[2], state[3]) != (state[0], state[1])) and ((state[2], state[3]) != (state[4], state[5])) and (
  496. (state[2], state[3]) not in Prepreki)
  497. and (state[3] < 10 and state[3] > 0) and (state[2] > 0 and state[2] < 8)):
  498. X = state[2]
  499. X = X - 1
  500. state = state[0], state[1], X, state[3], state[4], state[5]
  501. newState = state[2] + 1, state[3]
  502. return newState
  503.  
  504.  
  505. def doluO(state):
  506. while (((state[2], state[3]) != (state[0], state[1])) and ((state[2], state[3]) != (state[4], state[5])) and (
  507. (state[2], state[3]) not in Prepreki)
  508. and (state[3] < 10 and state[3] > 0) and (state[2] > 0 and state[2] < 8)):
  509. X = state[2]
  510. X = X + 1
  511. state = state[0], state[1], X, state[3], state[4], state[5]
  512. newState = state[2] - 1, state[3]
  513. return newState
  514.  
  515.  
  516. def desnoh2(state):
  517. while (((state[4], state[5]) != (state[0], state[1])) and ((state[4], state[5]) != (state[2], state[3])) and (
  518. (state[4], state[5]) not in Prepreki)
  519. and (state[5] < 10 and state[5] > 0) and (state[4] > 0 and state[4] < 8)):
  520. Y = state[5]
  521. Y = Y + 1
  522. state = state[0], state[1], state[2], state[3], state[4], Y
  523. newState = state[4], state[5] - 1
  524. return newState
  525.  
  526.  
  527. def levoh2(state):
  528. while (((state[4], state[5]) != (state[0], state[1])) and ((state[4], state[5]) != (state[2], state[3])) and (
  529. (state[4], state[5]) not in Prepreki)
  530. and (state[5] < 10 and state[5] > 0) and (state[4] > 0 and state[4] < 8)):
  531. Y = state[5]
  532. Y = Y - 1
  533. state = state[0], state[1], state[2], state[3], state[4], Y
  534. newState = state[4], state[5] + 1
  535. return newState
  536.  
  537.  
  538. def goreh2(state):
  539. while (((state[4], state[5]) != (state[0], state[1])) and ((state[4], state[5]) != (state[2], state[3])) and (
  540. (state[4], state[5]) not in Prepreki)
  541. and (state[5] < 10 and state[5] > 0) and (state[4] > 0 and state[4] < 8)):
  542. X = state[4]
  543. X = X - 1
  544. state = state[0], state[1], state[2], state[3], X, state[5]
  545. newState = state[4] + 1, state[5]
  546. return newState
  547.  
  548.  
  549. def doluh2(state):
  550. while (((state[4], state[5]) != (state[0], state[1])) and ((state[4], state[5]) != (state[2], state[3])) and (
  551. (state[4], state[5]) not in Prepreki)
  552. and (state[5] < 10 and state[5] > 0) and (state[4] > 0 and state[4] < 8)):
  553. X = state[4]
  554. X = X + 1
  555. state = state[0], state[1], state[2], state[3], X, state[5]
  556. newState = state[4] - 1, state[5]
  557. return newState
  558.  
  559.  
  560. class PMolekula(Problem):
  561. def __init__(self, initial):
  562. self.initial = initial
  563.  
  564. def goal_test(self, state):
  565. h1X = state[0]
  566. h1Y = state[1]
  567. oX = state[2]
  568. oY = state[3]
  569. h2X = state[4]
  570. h2Y = state[5]
  571. return (oX == h1X + 1 and h2X == oX + 1 and h1Y == oY and oY == h2Y)
  572.  
  573. def successor(self, state):
  574. successors = dict()
  575. h1 = state[0], state[1]
  576. o = state[2], state[3]
  577. h2 = state[4], state[5]
  578. # gore h1
  579. h1new = goreh1(state)
  580. newState = h1new[0], h1new[1], o[0], o[1], h2[0], h2[1]
  581. successors['GoreH1'] = newState
  582. # dolu h1
  583. h1new = doluh1(state)
  584. newState = h1new[0], h1new[1], o[0], o[1], h2[0], h2[1]
  585. successors['DoluH1'] = newState
  586. # desno h1
  587. h1new = desnoh1(state)
  588. newState = h1new[0], h1new[1], o[0], o[1], h2[0], h2[1]
  589. successors['DesnoH1'] = newState
  590. # levo h1
  591. h1new = levoh1(state)
  592. newState = h1new[0], h1new[1], o[0], o[1], h2[0], h2[1]
  593. successors['LevoH1'] = newState
  594. # desno o
  595. onew = desnoO(state)
  596. newState = h1[0], h1[1], onew[0], onew[1], h2[0], h2[1]
  597. successors['DesnoO'] = newState
  598. # dolu o
  599. onew = doluO(state)
  600. newState = h1[0], h1[1], onew[0], onew[1], h2[0], h2[1]
  601. successors['DoluO'] = newState
  602. # levo 0
  603. onew = levoO(state)
  604. newState = h1[0], h1[1], onew[0], onew[1], h2[0], h2[1]
  605. successors['LevoO'] = newState
  606. # gore o
  607. onew = goreO(state)
  608. newState = h1[0], h1[1], onew[0], onew[1], h2[0], h2[1]
  609. successors['GoreO'] = newState
  610. # dolu h2
  611. h2new = doluh2(state)
  612. newState = h1[0], h1[1], o[0], o[1], h2new[0], h2new[1]
  613. successors['DoluH2'] = newState
  614. # gore h2
  615. h2new = goreh2(state)
  616. newState = h1[0], h1[1], o[0], o[1], h2new[0], h2new[1]
  617. successors['GoreH2'] = newState
  618. # levo h2
  619. h2new = levoh2(state)
  620. newState = h1[0], h1[1], o[0], o[1], h2new[0], h2new[1]
  621. successors['LevoH2'] = newState
  622. # desno h2
  623. h2new = desnoh2(state)
  624. newState = h1[0], h1[1], o[0], o[1], h2new[0], h2new[1]
  625. successors['DesnoH2'] = newState
  626. return successors
  627.  
  628. def actions(self, state):
  629. return self.successor(state).keys()
  630.  
  631. # called only for informed search
  632. def h(self, node):
  633. pos = node.state
  634. goalState = self.goal
  635. return abs(pos[0] - goalState[0]) + abs(pos[1] - goalState[1])
  636.  
  637. def result(self, state, action):
  638. possible = self.successor(state)
  639. return possible[action]
  640.  
  641.  
  642. h1redica = int(input())
  643. h1kolona = int(input())
  644. oredica = int(input())
  645. okolona = int(input())
  646. h2redica = int(input())
  647. h2kolona = int(input())
  648. molekulaProblem = PMolekula((h1redica, h1kolona, oredica, okolona, h2redica, h2kolona))
  649. answer = breadth_first_graph_search(molekulaProblem)
  650. print(answer.solution())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement