Skip to content

Commit

Permalink
Merge branch 'leoscarlato-issue-52'
Browse files Browse the repository at this point in the history
fbarth committed Oct 3, 2024
2 parents 2030431 + 23b3339 commit 46c197b
Showing 12 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion aigyminsper/search/SearchAlgorithms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import deque
from aigyminsper.search.Graph import Node
from aigyminsper.search.graph import Node

def sortFunction(val):
"""
2 changes: 1 addition & 1 deletion aigyminsper/search/__init__.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
- SubidaMontanhaEstocastico: the class that implements the Stochastic Hill Climbing search algorithm.
"""

from .Graph import State
from .graph import State
from .SearchAlgorithms import (
SearchAlgorithm,
BuscaLargura,
10 changes: 8 additions & 2 deletions aigyminsper/search/Graph.py → aigyminsper/search/graph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module providing classes Node and State."""

from abc import ABC, abstractmethod
from abc import abstractmethod

class Node:
"""
@@ -43,7 +43,7 @@ def f(self):
return self.g + self.h()


class State(ABC):
class State:
"""
This class represents a state in a search problem.
This is an abstract class. This class defines the following abstract methods:
@@ -57,6 +57,12 @@ class State(ABC):
- print: returns a string with the operator that generated the current state
"""

def __init__(self,operator):
"""
- operator: the operator that generated the current state
"""
self.operator = operator

@abstractmethod
def successors(self):
"""
6 changes: 3 additions & 3 deletions docs/src/Puzzle8.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import result
from aicode.search.SearchAlgorithms import AEstrela
from aicode.search.Graph import State
from aigyminsper.search.SearchAlgorithms import AEstrela
from aigyminsper.search.graph import State
import math

class Puzzle8(State):
@@ -24,7 +24,7 @@ def copia_tabuleiro(self):
resultado[i][j] = self.tabuleiro[i][j]
return resultado

def sucessors(self):
def successors(self):
sucessors = []
lin, col = Puzzle8.onde_esta_N(self.tabuleiro, 0)
# zero para cima
6 changes: 3 additions & 3 deletions docs/src/U2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aicode.search.SearchAlgorithms import BuscaCustoUniforme
from aicode.search.Graph import State
from aigyminsper.search.SearchAlgorithms import BuscaCustoUniforme
from aigyminsper.search.graph import State

class U2(State):

@@ -15,7 +15,7 @@ def __init__(self, bono, edge, adam, larry, lanterna, op):
self.larry = larry
self.lanterna = lanterna

def sucessors(self):
def successors(self):
sucessors = []
if self.bono == self.lanterna:
sucessors.append(U2(not self.bono, self.edge, self.adam, self.larry, not self.lanterna, 'bono'))
5 changes: 1 addition & 4 deletions docs/src/VacuumWorldGeneric.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aigyminsper.search.SearchAlgorithms import AEstrela, BuscaGananciosa, BuscaLargura, BuscaProfundidade, BuscaProfundidadeIterativa
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State
import numpy
import sys

@@ -64,9 +64,6 @@ def description(self):

def cost(self):
return 1

def print(self):
return str(self.operator)

def env(self):
return str(self.mapa)+" "+str(self.lin)+" "+str(self.col)
18 changes: 9 additions & 9 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
In order to create an agent you must implement the `State` interface as shown below:

```python
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State

class MyAgent(State):

@@ -12,24 +12,24 @@ class MyAgent(State):
self.operator = op
# You must define how to represent the state
#TODO

def successors(self):
successors = []
#TODO
# you must define how to generate the successors for each operator (action)
return successors

def is_goal(self):
# You must define the goal state
pass

def description(self):
return "Problem description"

def cost(self):
# Return the cost of each operator (action)
return 1

def env(self):
#
# This methos is used to return a description of the state (environment).
@@ -38,9 +38,9 @@ class MyAgent(State):
None
```

You, as a developer, must implement the methods `successors`, `is_goal`, `description`, `cost`, and `env`, and describe how the world must be represented.
You, as a developer, must implement the methods `successors`, `is_goal`, `description`, `cost`, and `env`, and describe how the world must be represented.

The next step is define the best algorithm to solve the problem.
The next step is define the best algorithm to solve the problem.

```python
from aigyminsper.search.SearchAlgorithms import BuscaLargura
@@ -58,4 +58,4 @@ def main():

if __name__ == '__main__':
main()
```
```
2 changes: 1 addition & 1 deletion tests/AspiradorPo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aigyminsper.search.SearchAlgorithms import BuscaProfundidadeIterativa
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State

class AspiradorPo(State):

2 changes: 1 addition & 1 deletion tests/Equacao.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aigyminsper.search.CSPAlgorithms import SubidaMontanha, SubidaMontanhaEstocastico
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State
import numpy as np

class Equacao(State):
2 changes: 1 addition & 1 deletion tests/ProblemSpecificationExample.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aigyminsper.search.SearchAlgorithms import BuscaProfundidadeIterativa
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State

class ProblemSpecification(State):

5 changes: 2 additions & 3 deletions tests/SumOne.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from aigyminsper.search.SearchAlgorithms import BuscaLargura
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State

class SumOne(State):

def __init__(self, n, op, g):
# You must use this name for the operator!
self.operator = op
super().__init__(op)
self.number = n
self.goal = g

2 changes: 1 addition & 1 deletion tests/poi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aigyminsper.search.Graph import State
from aigyminsper.search.graph import State
from aigyminsper.search.SearchAlgorithms import BuscaLargura, BuscaProfundidadeIterativa
from aigyminsper.search.SearchAlgorithms import BuscaProfundidade,BuscaCustoUniforme

0 comments on commit 46c197b

Please sign in to comment.