从该数组创建和获取值的工作正常。我可以调整它的大小并用true
值填充它而没有问题。
class Solution
def initialize
@solution_matrix = [[[]]]
end
def [](receiver, provider, moment)
return @solution_matrix[receiver][provider][moment]
end
def []=(receiver, provider, moment, value)
puts "making " + receiver.to_s + " : " + provider.to_s + " : " +moment.to_s + " -> " + value.to_s
@solution_matrix[receiver][provider][moment] = value
end
当我尝试修改任何值时,问题就开始了。 @solution
是Solution
的实例:
@solution[2,3,15]=false;
控制台输出是:
making 2 : 3 : 15 -> false
一切似乎都没问题,但是当我尝试时:
def list_disconnected
number_of = 0
for receiver in 0...@problem.number_of_receivers
for provider in 0...@problem.number_of_providers
for moment in 0...@problem.number_of_moments
if (@solution[receiver,provider,moment]==false)
puts receiver.to_s + " : " + provider.to_s + " : " +moment.to_s
number_of += 1
end
end
end
end
puts number_of
end
它表明moment
15中的所有值都设置为false。用:
number of receivers: 40
number of providers: 6
number of moments: 50
我得到240个假细胞。