Method: CardType#max_flow

Defined in:
lib/manasimu/card.rb

#max_flow(lands, capas) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/manasimu/card.rb', line 321

def max_flow(lands, capas)
  obj = FordFulkersonSingleton.instance.obj
  # Graph has x+y+2 nodes
  # source       : 0
  # lands        : 1 - x 
  # mana_cost    : x+1 - x+y+1 
  # destination  : x+y+2
  #
  # image
  #         - land1  - mana4 
  # source0 - land2  - mana5 - destination6
  #         - land3 
  #

  # create edge
  x, y, e = edges(lands, capas)
  g = Graph.new(x + y + 2)
  e.each do |s, d|
    g.add_edge(s, d, 1)
  end

  ret = obj.max_flow(g, 0, x + y + 1)

  land_symbols = Array.new(lands.length)
  for edges in g.G do
    for edge in edges do
      if edge.cap == 0 and edge.from.between?(1, x) and edge.to.between?(x+1, x+y)
        land_index = edge.from - 1
        spell_index = edge.to - x - 1
        land_symbols[land_index] = symbols[spell_index] 
      end
    end
  end

  [ret, obj.used, land_symbols]
end