Class: MiniKraken::Glue::RunStarExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_kraken/glue/run_star_expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var_names, aGoal) ⇒ RunStarExpression

Returns a new instance of RunStarExpression.

Parameters:

  • var_names (String, Array<String>)

    One variable name or an array of names

  • aGoal (Core::Goal, Array<Core::Goal>)

    A single goal or an array of goals to conjunct



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

#ctxCore::Context (readonly)

Returns The context in which run* variables will be evaluated.

Returns:

  • (Core::Context)

    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

#goalCore::Goal (readonly)

Returns The main goal to satisfy.

Returns:



15
16
17
# File 'lib/mini_kraken/glue/run_star_expression.rb', line 15

def goal
  @goal
end

Instance Method Details

#runObject

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