diff --git a/pkg/search/search.go b/pkg/search/search.go index 0bbf7d4..5336ed0 100644 --- a/pkg/search/search.go +++ b/pkg/search/search.go @@ -15,77 +15,8 @@ package search import ( "github.com/rormartin/gosearch/internal/pkg/openlist" - "strconv" ) -// State is a basic state represtation for search algorithms -type State interface { - - // For and input action, the function generates a new state with - // the new action included - ApplyAction(action Action) State - - // Returns the list of actions applied to the state to research the - // actual state - GetPartialSolution() []Action - - // Returns the sum of all the costs for all the actions applied - // to the actual state - GetSolutionCost() float64 - - // For a given action, the funcion determinate if is possible to - // apply that action to the state - // isValidAction(action Action) bool - - // Method that generate a list of all the possible applicable actions - // for the current state - GetApplicableActions() []Action - - // Returns if the actual state is a solution state - IsSolution() bool - - // Compare two states - Equal(second State) bool - - // Add the action to the current state - // addActionToSolution(action Action) - - // Returns the depth in the search tree of the current state - GetStateLevel() int - - // the heuristic evaluation for a state - Heuristic() float64 - - // Default string representation (mainly for debug) - String() string -} - -// Action interface to represent the cost of an action -type Action interface { - // represents the float cost for an Action - Cost() float64 -} - -// Statistics information about the state space explored by the search -type Statistics struct { - NodesExplored int - NodesDuplicated int - MaxDepth int - Solutions int -} - -// Basic string default representation for the Statistics -func (stats Statistics) String() string { - - return "[" + - "NodesExplored: " + strconv.Itoa(stats.NodesExplored) + ", " + - "NodesDuplicated: " + strconv.Itoa(stats.NodesDuplicated) + ", " + - "MaxDepth: " + strconv.Itoa(stats.MaxDepth) + ", " + - "Solutions: " + strconv.Itoa(stats.Solutions) + - "]" - -} - // Search mechanism // SearchBreadthFirst is a basic search without domain information diff --git a/pkg/search/search_models.go b/pkg/search/search_models.go new file mode 100644 index 0000000..7f7213b --- /dev/null +++ b/pkg/search/search_models.go @@ -0,0 +1,62 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package search + +// State is a basic state represtation for search algorithms +type State interface { + + // For and input action, the function generates a new state with + // the new action included + ApplyAction(action Action) State + + // Returns the list of actions applied to the state to research the + // actual state + GetPartialSolution() []Action + + // Returns the sum of all the costs for all the actions applied + // to the actual state + GetSolutionCost() float64 + + // For a given action, the funcion determinate if is possible to + // apply that action to the state + // isValidAction(action Action) bool + + // Method that generate a list of all the possible applicable actions + // for the current state + GetApplicableActions() []Action + + // Returns if the actual state is a solution state + IsSolution() bool + + // Compare two states + Equal(second State) bool + + // Add the action to the current state + // addActionToSolution(action Action) + + // Returns the depth in the search tree of the current state + GetStateLevel() int + + // the heuristic evaluation for a state + Heuristic() float64 + + // Default string representation (mainly for debug) + String() string +} + +// Action interface to represent the cost of an action +type Action interface { + // represents the float cost for an Action + Cost() float64 +} diff --git a/pkg/search/search_statistic.go b/pkg/search/search_statistic.go new file mode 100644 index 0000000..67ea363 --- /dev/null +++ b/pkg/search/search_statistic.go @@ -0,0 +1,38 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package search + +import ( + "strconv" +) + +// Statistics information about the state space explored by the search +type Statistics struct { + NodesExplored int + NodesDuplicated int + MaxDepth int + Solutions int +} + +// Basic string default representation for the Statistics +func (stats Statistics) String() string { + + return "[" + + "NodesExplored: " + strconv.Itoa(stats.NodesExplored) + ", " + + "NodesDuplicated: " + strconv.Itoa(stats.NodesDuplicated) + ", " + + "MaxDepth: " + strconv.Itoa(stats.MaxDepth) + ", " + + "Solutions: " + strconv.Itoa(stats.Solutions) + + "]" + +} diff --git a/pkg/search/gsearch.go b/pkg/search/uninformed_search.go similarity index 100% rename from pkg/search/gsearch.go rename to pkg/search/uninformed_search.go diff --git a/pkg/search/aux.go b/pkg/search/utils.go similarity index 100% rename from pkg/search/aux.go rename to pkg/search/utils.go