Class: Relax4::IntegerArray

Inherits:
Object
  • Object
show all
Defined in:
lib/relax4.rb

Overview

Provided by SWIG for exchanging data with the solver. Intended for internal use; see relax4_init in relax4.h, above. You do not have to use this if you call solve.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_array(a) ⇒ IntegerArray

Create from Ruby Array of Integers; creates C array of appropriate length and copies the Ruby values in.

Parameters:

  • a (Array<Integer>)

    elements to assign to new IntegerArray

Returns:



299
300
301
302
# File 'lib/relax4.rb', line 299

def self.from_array a
  ia = self.new(a.size) or raise 'failed to create IntegerArray'
  ia.assign! a
end

Instance Method Details

#assign!(a) ⇒ IntegerArray

Set elements from Ruby Array; array length is not checked.

because array bounds are not checked.

Parameters:

  • a (Array<Integer>)

    elements to assign; must be of correct size,

Returns:



312
313
314
315
316
317
# File 'lib/relax4.rb', line 312

def assign! a
  for i in 0...a.size
    self[i] = a[i]
  end
  self
end

#to_a!(size) ⇒ Array<Integer>

Convert to Ruby Array of given size; array length is not checked.

Returns:

  • (Array<Integer>)

    with given size



324
325
326
327
328
329
330
# File 'lib/relax4.rb', line 324

def to_a! size
  a = Array.new(size)
  for i in 0...a.size
    a[i] = self[i]
  end
  a
end