Sha256: e95537e226ec337c533c490e10b7acb02cefca7f3e9bb3bb7ab9c929f977f3f4

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

require File.dirname(__FILE__) + '/example_helper'

# An example of using the raw bindings. Solves the send+more=money problem.

# Variables
space = Gecode::Raw::Space.new
letters = Gecode::Raw::IntVarArray.new(space, 8, 0, 9)
space.own(letters, 'letters')
s, e, n, d, m, o, r, y = (0..7).to_a.map{ |i| letters.at(i) }

# Constraints
Gecode::Raw::post(space, (s * 1000 + e * 100 + n * 10  + d   + 
                     m * 1000 + o * 100 + r * 10  + e).
            equal(m * 10000 + o * 1000 + n * 100 + e * 10  + y ), 
            Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
Gecode::Raw::rel(space, s, Gecode::Raw::IRT_NQ, 0, Gecode::Raw::ICL_DEF, 
  Gecode::Raw::PK_DEF)
Gecode::Raw::rel(space, m, Gecode::Raw::IRT_NQ, 0, Gecode::Raw::ICL_DEF, 
  Gecode::Raw::PK_DEF)
Gecode::Raw::distinct(space, letters, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)

# Branching.
Gecode::Raw::branch(space, letters, 
  Gecode::Raw::INT_VAR_SIZE_MIN, Gecode::Raw::INT_VAL_MIN)

# Search
COPY_DIST = 16
ADAPTATION_DIST = 4 
dfs = Gecode::Raw::DFS.new(space, COPY_DIST, ADAPTATION_DIST, 
  Gecode::Raw::Search::Stop.new)

space = dfs.next
if space.nil?
  puts 'Failed'
else
  puts 'Solution:'
  correct_letters = space.intVarArray('letters')
  arr = []
  correct_letters.size.times do |i|
    arr << correct_letters.at(i).val
  end
  puts arr.join(' ')
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
gecoder-with-gecode-0.8.2-mswin32 example/raw_bindings.rb
gecoder-with-gecode-0.8.1-mswin32 example/raw_bindings.rb
gecoder-0.8.2 example/raw_bindings.rb
gecoder-0.8.1 example/raw_bindings.rb
gecoder-with-gecode-0.8.1 example/raw_bindings.rb
gecoder-with-gecode-0.8.2 example/raw_bindings.rb