class RAMS::Constraint

A RAMS::Constraint must take the form:

lhs ==|<=|>= rhs

lhs is a hash of variables to coefficients and rhs is a constant. The sense is the sense of the inequality and must be closed.

Attributes

id[R]
lhs[R]
rhs[R]
sense[R]

Public Class Methods

new(lhs, sense, rhs) click to toggle source
# File lib/rams/constraint.rb, line 12
def initialize(lhs, sense, rhs)
  @id = Variable.next_id

  @lhs = lhs.dup
  @sense = sense
  @rhs = rhs

  validate
end
next_id() click to toggle source
# File lib/rams/constraint.rb, line 28
def self.next_id
  @next_id += 1
end

Public Instance Methods

name() click to toggle source
# File lib/rams/constraint.rb, line 22
def name
  "c#{id}"
end

Private Instance Methods

validate() click to toggle source
# File lib/rams/constraint.rb, line 34
def validate
  validate_lhs
  validate_sense
  validate_rhs
end
validate_lhs() click to toggle source
# File lib/rams/constraint.rb, line 40
def validate_lhs
  raise(ArgumentError, 'invalid lhs') if lhs.empty?
end
validate_rhs() click to toggle source
# File lib/rams/constraint.rb, line 48
def validate_rhs
  raise(ArgumentError, 'invalid rhs') unless rhs.is_a? Numeric
end
validate_sense() click to toggle source
# File lib/rams/constraint.rb, line 44
def validate_sense
  raise(ArgumentError, 'invalid sense') unless [:<=, :==, :>=].index(sense)
end