Package org.evoludo.simulator.modules
Class Continuous.Traits2Payoff
Object
Traits2Payoff
- Enclosing class:
Continuous
Translate continuous traits into payoffs based on configurable cost and
benefit functions.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Continuous.Benefits[]
The array of benefit functions, one for each trait.(package private) double[][]
The 2D array of cost function parameters.(package private) double[][]
The 2D array of cost function parameters.(package private) Continuous.Costs[]
The array of cost functions, one for each trait. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected double
benefits
(double[] me, double[] you) Calculate the benefits to the focal individual with traitsme
when interacting with an opponent with traitsyou
.protected double
benefits
(double me, double you, int trait) Calculate the benefits to the focal individual with trait valueme
in trait with indextrait
when interacting with an opponent with trait valueyou
.protected double
costs
(double[] me, double[] you) Calculate the costs to the focal individual with traitsme
when interacting with an opponent with traitsyou
.protected double
costs
(double me, double you, int trait) Calculate the costs to the focal individual with trait valueme
in trait with indextrait
when interacting with an opponent with trait valueyou
.formatBenefits
(int idx) Return formatted string of the benefit function of trait indexidx
.formatCosts
(int idx) Return formatted string of the cost function of trait indexidx
.getBenefitFunction
(int index) Get the benefit function for traitindex
.Get the array of benefit functions for each trait.double[][]
Get the 2D array of benefit function parameters.double[]
getBenefitParameters
(int index) Get the array of benefit function parameters for trait with indexidx
.getCostFunction
(int index) Get the cost function for traitindex
.Get the array of cost functions, one for each trait.double[][]
Get the 2D array of cost function parameters.double[]
getCostParameters
(int index) Get the array of cost function parameters for trait with indexidx
.double
payoff
(double[] me, double[] you) Calculate the payoff to the focal individual with traitsme
when interacting with an opponent with traitsyou
.double
payoff
(double me, double you) Calculate the payoff to the focal individual with traitme
when interacting with an opponent with traityou
.void
setBenefitFunction
(Continuous.Benefits benefitfcn, double[] bparams, int index) Set the benefit function of the traitindex
tobenefitfcn
.void
setBenefitParameters
(double[] bparams, int index) Set the array of benefit function parameters for trait with indexidx
to arrayparams
.void
setCostFunction
(Continuous.Costs costfcn, double[] cparams, int index) Set the cost function of the traitindex
tocostfcn
with parameters in the arraycparams
.void
setCostParameters
(double[] cparams, int index) Set the array of cost function parameters for trait with indexidx
to arrayparams
.
-
Field Details
-
costs
Continuous.Costs[] costsThe array of cost functions, one for each trait. -
ci
double[][] ciThe 2D array of cost function parameters. The rows refer to the different traits and the columns to their cost parameters.ci
is not necessarily a square array because the each trait may have different numbers of parameters.- See Also:
-
benefits
Continuous.Benefits[] benefitsThe array of benefit functions, one for each trait. -
bi
double[][] biThe 2D array of cost function parameters. The rows refer to the different traits and the columns to their cost parameters.bi
is not necessarily a square array because the each trait may have different numbers of parameters.- See Also:
-
-
Constructor Details
-
Traits2Payoff
public Traits2Payoff()Constructs a new map for converting traits into oayoffs.
-
-
Method Details
-
getCostFunctions
Get the array of cost functions, one for each trait.- Returns:
- the array of cost functions
-
getCostFunction
Get the cost function for traitindex
.- Parameters:
index
- the index of the trait- Returns:
- the cost function
-
setCostFunction
Set the cost function of the traitindex
tocostfcn
with parameters in the arraycparams
.- Parameters:
costfcn
- the cost functioncparams
- the array of parameters forcostfcn
index
- the index of the trait
-
setCostParameters
public void setCostParameters(double[] cparams, int index) Set the array of cost function parameters for trait with indexidx
to arrayparams
.- Parameters:
cparams
- the array of cost function parametersindex
- the index of the trait- See Also:
-
getCostParameters
public double[] getCostParameters(int index) Get the array of cost function parameters for trait with indexidx
.- Parameters:
index
- the index of the trait- Returns:
- the array of cost function parameters
- See Also:
-
getCostParameters
public double[][] getCostParameters()Get the 2D array of cost function parameters.- Returns:
- the 2D array of cost function parameters
- See Also:
-
formatCosts
Return formatted string of the cost function of trait indexidx
.- Parameters:
idx
- the index of the trait- Returns:
- the formatted string
-
getBenefitFunctions
Get the array of benefit functions for each trait.- Returns:
- the array of benefit functions
-
getBenefitFunction
Get the benefit function for traitindex
.- Parameters:
index
- the index of the trait- Returns:
- the benefit function
-
setBenefitFunction
Set the benefit function of the traitindex
tobenefitfcn
.- Parameters:
benefitfcn
- the benefit functionbparams
- the array of benefit function parametersindex
- the index of the trait
-
setBenefitParameters
public void setBenefitParameters(double[] bparams, int index) Set the array of benefit function parameters for trait with indexidx
to arrayparams
.- Parameters:
bparams
- the array of benefit function parametersindex
- the index of the trait- See Also:
-
getBenefitParameters
public double[] getBenefitParameters(int index) Get the array of benefit function parameters for trait with indexidx
.- Parameters:
index
- the index of the trait- Returns:
- the array of benefit function parameters
- See Also:
-
getBenefitParameters
public double[][] getBenefitParameters()Get the 2D array of benefit function parameters.- Returns:
- the 2D array of benefit function parameters
- See Also:
-
formatBenefits
Return formatted string of the benefit function of trait indexidx
.- Parameters:
idx
- the index of the trait- Returns:
- the formatted string
-
payoff
public double payoff(double[] me, double[] you) Calculate the payoff to the focal individual with traitsme
when interacting with an opponent with traitsyou
.- Parameters:
me
- the array of traits of the focal individualyou
- the array of traits of the opponent individual- Returns:
- the payoff to
me
-
payoff
public double payoff(double me, double you) Calculate the payoff to the focal individual with traitme
when interacting with an opponent with traityou
.- Parameters:
me
- the trait of the focal individualyou
- the trait of the opponent individual- Returns:
- the payoff to
me
-
costs
protected double costs(double[] me, double[] you) Calculate the costs to the focal individual with traitsme
when interacting with an opponent with traitsyou
.- Parameters:
me
- the array of traits of the focal individualyou
- the array of traits of the opponent individual- Returns:
- the costs to
me
-
costs
protected double costs(double me, double you, int trait) Calculate the costs to the focal individual with trait valueme
in trait with indextrait
when interacting with an opponent with trait valueyou
.- Parameters:
me
- the trait value of the focal individualyou
- the trait value of the opponent individualtrait
- the index of the trait- Returns:
- the costs to
me
-
benefits
protected double benefits(double[] me, double[] you) Calculate the benefits to the focal individual with traitsme
when interacting with an opponent with traitsyou
.- Parameters:
me
- the array of traits of the focal individualyou
- the array of traits of the opponent individual- Returns:
- the benefits to
me
-
benefits
protected double benefits(double me, double you, int trait) Calculate the benefits to the focal individual with trait valueme
in trait with indextrait
when interacting with an opponent with trait valueyou
.- Parameters:
me
- the trait value of the focal individualyou
- the trait value of the opponent individualtrait
- the index of the trait- Returns:
- the benefits to
me
-