PageRenderTime 21ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/backtracking/backtracking.e

http://github.com/tybor/Liberty
Specman e | 123 lines | 59 code | 10 blank | 54 comment | 0 complexity | 09f5c509cf560fee8c38957d23844101 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4deferred class BACKTRACKING
  5   --
  6   -- This class is intended to explore structures that matches the and/or
  7   -- graph of BACKTRACKING_NODE. The alternatives have a context that
  8   -- gotten and restored using the features 'get_context' and 'restore_context'.
  9   --
 10   -- See tutorial/backtracking for examples.
 11   --
 12   -- The instances of the BACKTRACKING children are typically
 13   -- used through lines like the following ones that enumerate the
 14   -- solutions:
 15   --
 16   --         from
 17   --            set_current_node(root)
 18   --            search_first
 19   --         until
 20   --            is_off
 21   --         loop
 22   --            ... -- do something
 23   --            search_next
 24   --         end
 25   --
 26   -- These features are declared to be bound to ANY but don't hesitate to
 27   -- change the type of the context to what your context is.
 28   --
 29
 30inherit
 31   ABSTRACT_BACKTRACKING
 32
 33insert
 34   BACKTRACKING_GLOBALS
 35
 36feature {ANY}
 37   set_current_node (node: like current_node)
 38         -- Sets the next node of the BACKTRACKING_NODE graph to evaluate.
 39      do
 40         current_node := node
 41      ensure
 42         definition: current_node = node
 43      end
 44
 45   push_and (node: BACKTRACKING_NODE)
 46         -- Pushes `node' in front of the continuation path.
 47      require
 48         node_not_void: node /= Void
 49      local
 50         sequence: BACKTRACKING_SEQUENCE
 51      do
 52         sequence := pool_of_sequence.get_instance
 53         sequence.set_next(node)
 54         push_sequence(sequence)
 55      end
 56
 57   push_and_list (list: BACKTRACKING_NODE_AND_LIST)
 58         -- Pushes `list' in front of the continuation path.
 59      require
 60         list_not_void: list /= Void
 61      local
 62         sequence: BACKTRACKING_SEQUENCE_LIST
 63      do
 64         sequence := pool_of_sequence_list.get_instance
 65         sequence.set_list(list)
 66         push_sequence(sequence)
 67      end
 68
 69   push_or (node: BACKTRACKING_NODE)
 70         -- Pushes `node' in front of the possible alternatives.
 71      require
 72         node_not_void: node /= Void
 73      local
 74         alternative: BACKTRACKING_ALTERNATIVE
 75      do
 76         alternative := pool_of_alternative.get_instance
 77         alternative.set_next(node)
 78         push_alternative(alternative)
 79      end
 80
 81   push_or_list (list: BACKTRACKING_NODE_OR_LIST)
 82         -- Pushes `list' in front of the possible alternatives.
 83      require
 84         list_not_void: list /= Void
 85      local
 86         alternative: BACKTRACKING_ALTERNATIVE_LIST
 87      do
 88         alternative := pool_of_alternative_list.get_instance
 89         alternative.set_list(list)
 90         push_alternative(alternative)
 91      end
 92
 93feature {} -- internal
 94   current_node: BACKTRACKING_NODE
 95         -- Current node of the BACKTRACKING_NODE graph to be evaluated.
 96
 97   evaluate_current_state
 98         -- That feature is called to evaluate the current state
 99      do
100         current_node.explore(Current)
101      end
102
103end -- class BACKTRACKING
104--
105-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
106--
107-- Permission is hereby granted, free of charge, to any person obtaining a copy
108-- of this software and associated documentation files (the "Software"), to deal
109-- in the Software without restriction, including without limitation the rights
110-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111-- copies of the Software, and to permit persons to whom the Software is
112-- furnished to do so, subject to the following conditions:
113--
114-- The above copyright notice and this permission notice shall be included in
115-- all copies or substantial portions of the Software.
116--
117-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
118-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
119-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
120-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
121-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
122-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
123-- THE SOFTWARE.