From: Saverio Lasala on 16 Mar 2010 14:03 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[i] 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 -- Posted via http://www.ruby-forum.com/.  |  Pages: 1 Prev: array.eachNext: Question about the evaluation of x = 'foo' if false