Class: Gecode::Constraints::SetEnum::Expression

Inherits:
Expression
  • Object
show all
Defined in:
lib/gecoder/interface/constraints/set_enum_constraints.rb,
lib/gecoder/interface/constraints/set_enum/channel.rb,
lib/gecoder/interface/constraints/set_enum/distinct.rb

Overview

Expressions with set enums as left hand sides.

Instance Method Summary collapse

Constructor Details

#initialize(model, params) ⇒ Expression

Raises TypeError unless the left hand side is a set enum.



20
21
22
23
24
25
26
# File 'lib/gecoder/interface/constraints/set_enum_constraints.rb', line 20

def initialize(model, params)
  super
  
  unless params[:lhs].respond_to? :to_set_var_array
    raise TypeError, 'Must have set enum as left hand side.'
  end
end

Instance Method Details

#at_most_share_one_element(options = {}) ⇒ Object

Adds a constraint on the sets that specifies that they must have at most one element in common. The “option” :size must be specified, the sets will be constrained to that size.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gecoder/interface/constraints/set_enum/distinct.rb', line 6

def at_most_share_one_element(options = {})
  unless options.has_key? :size
    raise ArgumentError, 'Option :size has to be specified.'
  end
  unless options.size == 1
    raise ArgumentError, 'Only the option :size is accepted, got ' + 
      "#{options.keys.join(', ')}."
  end
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated atmost one ' + 
      'constrain is not implemented.'
  end
  
  @model.add_constraint Distinct::AtMostOneConstraint.new(
    @model, @params.update(options))
end

#channel(enum, options = {}) ⇒ Object

Posts a channel constraint on the variables in the enum with the specified int enum.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gecoder/interface/constraints/set_enum/channel.rb', line 5

def channel(enum, options = {})
  unless enum.respond_to? :to_int_var_array
    raise TypeError, "Expected integer variable enum, for #{enum.class}."
  end
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated channel constraint ' + 
      'is not implemented.'
  end
  if options.has_key? :reify
    raise ArgumentError, 'The channel constraints does not support the ' +
      'reification option.'
  end
  
  @params.update(Gecode::Constraints::Set::Util.decode_options(options))
  @params.update(:rhs => enum)
  @model.add_constraint Channel::IntChannelConstraint.new(@model, @params)
end