Class: Ropt::CooperativeGames::ShapleyValue

Inherits:
Object
  • Object
show all
Defined in:
lib/ropt/cooperative_games/shapley_value.rb

Overview

class for calculating of Shapley Value something super-additive convex cooperative game

Constant Summary collapse

DEFAULT_VALUE_OF_COALITION =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coalitions, number_gamers, round = 3) ⇒ ShapleyValue



10
11
12
13
14
15
16
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 10

def initialize(coalitions, number_gamers, round = 3)
  @coalitions = coalitions
  @number_gamers = number_gamers
  @coefficients = Ropt::CooperativeGames::CoalitionsCoefficients.new(number_gamers).call
  @validator = Ropt::CooperativeGames::Validator.new
  @round = round
end

Instance Attribute Details

#coalitionsObject

Returns the value of attribute coalitions.



7
8
9
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 7

def coalitions
  @coalitions
end

#coefficientsObject

Returns the value of attribute coefficients.



7
8
9
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 7

def coefficients
  @coefficients
end

#number_gamersObject

Returns the value of attribute number_gamers.



7
8
9
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 7

def number_gamers
  @number_gamers
end

#roundObject

Returns the value of attribute round.



7
8
9
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 7

def round
  @round
end

#validatorObject

Returns the value of attribute validator.



7
8
9
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 7

def validator
  @validator
end

Instance Method Details

#solveObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ropt/cooperative_games/shapley_value.rb', line 18

def solve
  validator.validate_arguments(coefficients,
                               coalitions,
                               number_gamers)

  singletons = singleton_coalitions

  validator.validate_coalitions_consistency(coalitions, singletons.keys)

  vector = calculate_vector_shapley(singletons)

  validator.validate_result(coalitions, singletons.keys, vector)

  vector
end