The model assumes that the market demand curve and the marginal cost curve for each firm are straight lines. The following tables define the parameters of these lines and show some theoretical solution values.
| PARAMETER | SYMBOL |
|---|---|
| Price Intercept of Market Demand Function | a |
| Quantity Intercept of Market Demand Function | a/b |
| Additive Inverse of Slope of Market Demand Function | b |
| Number of Firms | n |
| Price Intercept of Firm Marginal Cost Function | c |
| Slope of Firm Marginal Cost Function | d |
| TOTAL QUANTITY SUPPLIED TO MARKET | QUANTITY SUPPLIED BY EACH FIRM | PRICE | |
|---|---|---|---|
| Monopoly | (a-c)/(2 b + d) | (a-c)/(2 b + d) | (a b + a d + b c)/(2 b + d) |
| Cournot | n (a-c)/[(n + 1) b + d] | (a-c)/[(n + 1) b + d] | (a b + a d + n b c)/[(n + 1) b + d] |
| Perfect Competition | (a-c)/b | 0 | c |
The most important code fragment is:
private double firmAlgorithm( double prevQuantity, int firm )
{
double currentStep;
int lastTime;
double currentQuantity;
// Find the most recent period in which the quantity produced by the
// firm was changed from the prior period.
boolean isFound = false;
lastTime = currentTime - 1;
for ( int lastTime2 = currentTime - 1;
( ! isFound ) && ( lastTime2 > 0 ); lastTime2-- ) {
isFound = ( firmQuantity[ firm ][ lastTime2 ]
!= firmQuantity[ firm ][ lastTime2 - 1 ] );
lastTime = lastTime2;
}
if ( isFound ) {
// Determine last change in quantity.
double deltaQuantity = firmQuantity[ firm ][ lastTime ]
- firmQuantity[ firm ][ lastTime - 1 ];
// Determine change in profit resulting from last variation in
// quantity.
double profit = marketPrice[ lastTime ] * firmQuantity[ firm ][ lastTime ]
- TotalCost( firmQuantity[ firm ][ lastTime ] );
double laggedProfit = marketPrice[ lastTime - 1 ]
* firmQuantity[ firm ][ lastTime - 1 ]
- TotalCost( firmQuantity[ firm ][ lastTime - 1 ] );
double deltaProfit = profit - laggedProfit;
// If last change increased profit, set current period's quantity change
// to be in same direction. Otherwise, set current period's quantity
// change in the opposite direction.
if ( deltaProfit > 0 ) {
if ( deltaQuantity > 0 ) {
currentStep = stepSize;
} else {
currentStep = - stepSize;
}
} else {
if ( deltaQuantity > 0 ) {
currentStep = - stepSize;
} else {
currentStep = stepSize;
}
}
// If the firm acts irrationally this period, reverse the direction of
// the current period's quantity change.
if ( generator.nextFloat() < irrationalityRate ) {
currentStep = - currentStep;
}
// Update the quantity the firm produces.
currentQuantity = prevQuantity + currentStep;
} else {
// This firm has never changed its quantity before. So increment
// the quantity produced by the firm in the previously-determined
// random direction.
if ( isFirstStepPositive[ firm ] ) {
currentQuantity = prevQuantity + stepSize;
} else {
currentQuantity = prevQuantity - stepSize;
}
}
// If the algorithm resulted in a negative level of production, reset
// the quantity produced by the firm to zero.
if ( currentQuantity < 0.0 ) {
currentQuantity = 0.0;
}
return currentQuantity;
}