gecode/r troubles with constraints definition in a CSP

S

Saverio Lasala

Hi,
i'm trying the Gecoder-with-gecode library, to solve some CSP problems.

The problem is: given a int_matrix (with domain 0..1),

sched = int_var_matrix(3, 15,0..1)

place 0 and 1's in order to respect the following constraints:

1) the sum of each column's value must be 1:

sched.column_size.times do |j|
col=sched.column(j).to_a
sumc=int_var
sumc=col.inject{|sum,x| sum+x}
sumc.must==1
end

2) the sum of each row's value must be equal to a given array content:

times=[3,4,3] # the array

sched.row_size.times do |i|
ro=sched.row(i).to_a
sumr=int_var
sumr=ro.inject{|sum,y| sum+y}
sumr.must==times
end

The 1) and 2) work well, but when i put the 3rd:

3) each row, the first "1" from left, must be positioned after a
specific index, contained in an array

starts=[7,3,0] # the array

sched.row_size.times do |w|
ro=sched.row(w).to_a
sumg=int_var
sumg=ro.index(1) {|i| puts i}
sumg.must >= starts
end

if i keep just the 1) and 2) and do:

branch_on matricione
solve!

i obtain a solution, but when i put the 3), it appears the following
error:
`method_missing': undefined method `must' for nil:NilClass
(NoMethodError)
from scheduling.rb:55

This is strange, because the 3) is very similar to the other ones!!
Anyone can help me please?
Thanks
Saverio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top