Class: MiniKraken::Glue::RunStarExpression
- Inherits:
-
Object
- Object
- MiniKraken::Glue::RunStarExpression
- Defined in:
- lib/mini_kraken/glue/run_star_expression.rb
Instance Attribute Summary collapse
-
#ctx ⇒ Core::Context
readonly
The context in which run* variables will be evaluated.
-
#goal ⇒ Core::Goal
readonly
The main goal to satisfy.
Instance Method Summary collapse
-
#initialize(var_names, aGoal) ⇒ RunStarExpression
constructor
A new instance of RunStarExpression.
-
#run ⇒ Object
Run the query, that is, try to find ALL solutions of the provided qoal.
Constructor Details
#initialize(var_names, aGoal) ⇒ RunStarExpression
Returns a new instance of RunStarExpression.
19 20 21 22 23 |
# File 'lib/mini_kraken/glue/run_star_expression.rb', line 19 def initialize(var_names, aGoal) @ctx = Core::Context.new ctx.add_vars(var_names) @goal = Rela::Fresh.compose_goals(aGoal) end |
Instance Attribute Details
#ctx ⇒ Core::Context (readonly)
Returns The context in which run* variables will be evaluated.
12 13 14 |
# File 'lib/mini_kraken/glue/run_star_expression.rb', line 12 def ctx @ctx end |
#goal ⇒ Core::Goal (readonly)
Returns The main goal to satisfy.
15 16 17 |
# File 'lib/mini_kraken/glue/run_star_expression.rb', line 15 def goal @goal end |
Instance Method Details
#run ⇒ Object
Run the query, that is, try to find ALL solutions of the provided qoal. One solution corresponds to allowed value associated to the provided logical variable(s).
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mini_kraken/glue/run_star_expression.rb', line 30 def run result = [] solver = goal.achieve(ctx) # A solver == Fiber(-like) yielding Context # require 'debug' loop do outcome = solver.resume(ctx) break if outcome.nil? # No other solution? result << outcome.build_solution.values if outcome.success? end format_solutions(result) end |