Public Member Functions | |
void | addSeller (ISeller pSeller) |
Add a Seller of goods of the Sector Suppliers.inputSector which supplies getBAUSupply() to the list of potential suppliers in the trade phase. | |
void | addExtraSeller (ISeller pSeller) |
Add a Seller of goods of the Sector Suppliers.inputSector which supplies getExtraSupply() to the list of potential suppliers in the trade phase. | |
void | replaceSeller (int pIndex, ISeller pSeller) |
In Suppliers.inputSector, replace a seller supplying getBAUSupply() by a new one supplying getExtraSupply(). | |
Package Types | |
enum | SellerSet |
If the SellerSet parameter of Suppliers.findSuppliers is set to INCLUDE_IMPORT, the ImportExport agent for the sector corresponding to Suppliers.inputSector will be added to the list of Suppliers.sellingFirms. More... | |
Package Functions | |
void | init (Foundation pFoundation, IBuyer pBuyer, Sector pSector, double pFirmsToObserveQuotient) |
Initialize the Suppliers instance. | |
void | findSuppliers (SellerSet pSellerSet) |
Observe FirmInitValues.numObservedFirms that have a not empty inventory stock and add them to the sellingFirms array. | |
void | updateSuppliers (SellerSet pSellerSet) |
Rearrange the list of supppliers and replace suppliers which are too expensive. | |
void | addSuppliers (double pDemand, SellerSet pSellerSet) |
Add suppliers in case of rationing,. | |
double | maxSupply () |
Return the total unit of goods that the suppliers can deliver. | |
double | costOfTotalStock () |
Return the total cost of the stock that the suppliers can deliver. | |
double | buy (double pAmount) |
Buy pAmount of the good produced by the inputSector from the firms in the supplierList. | |
double | buyValue (double pValue) |
Buy for a value of pValue the good produced by the inputSector from the firms in the supplierList. | |
double | averagePrice () |
Calculate the average price for which the good is offered by the found suppliers. | |
Private Member Functions | |
int | getMostExpensiveSupplier () |
Buy pAmount of the good produced by the inputSector from the firms in the supplierList. | |
Private Attributes | |
Sector | inputSector |
The sector under consideration in the supplier search. | |
ISeller[] | sellingFirms = new ISeller[100] |
The list of firms from the sector Suppliers.inputSector that have a non-empty inventory when findSuppliers is called. | |
int | numFoundFirms = 0 |
A counter for the number of selling firms already found. | |
double | firmsToObserveQuotient |
The number of selling firms to be observed is calculated by multiplying the number of firms in the supplying sector with this quotient. | |
IBuyer | buyer |
The agent that is observing the firms. | |
double | maxSupply = 0 |
The sum of goods of all firms in the Suppliers.sellingFirms array. | |
double | costOfTotalStock = 0 |
The money that would be needed for buying the inventory of all firms in the Suppliers.sellingFirms array. | |
RandomGenerator | random = null |
The random generator. | |
Classes | |
class | NumFirmsToObserveTable |
A lookup table which determines the number of firms to observe. More... | |
class | Probe |
Definition at line 41 of file Suppliers.java.
enum SellerSet [package] |
If the SellerSet parameter of Suppliers.findSuppliers is set to INCLUDE_IMPORT, the ImportExport agent for the sector corresponding to Suppliers.inputSector will be added to the list of Suppliers.sellingFirms.
Definition at line 47 of file Suppliers.java.
void init | ( | Foundation | pFoundation, | |
IBuyer | pBuyer, | |||
Sector | pSector, | |||
double | pFirmsToObserveQuotient | |||
) | [package] |
Initialize the Suppliers instance.
Definition at line 219 of file Suppliers.java.
Referenced by ImportExport.init(), Household.init(), and Firm.initArraysAndMatrices().
00219 { 00220 foundation = pFoundation; 00221 buyer = pBuyer; 00222 inputSector = pSector; 00223 firmsToObserveQuotient = pFirmsToObserveQuotient; 00224 random = Foundation.getRandomGenerator(); 00225 00226 00227 // prepare the cache for the pre-calculated tables 00228 if (numFirmsToObserveTableCache == null) { 00229 numFirmsToObserveTableCache = new Cache<Double, FixedIntTable>(new Cache.ValueCalculator<Double, FixedIntTable>() { 00230 public FixedIntTable calc(Double pKey) { 00231 return new NumFirmsToObserveTable(pKey).getTable(); 00232 } 00233 }); 00234 } 00235 00236 numFirmsToObserveTable = numFirmsToObserveTableCache.get(firmsToObserveQuotient); 00237 }
void findSuppliers | ( | SellerSet | pSellerSet | ) | [package] |
Observe FirmInitValues.numObservedFirms that have a not empty inventory stock and add them to the sellingFirms array.
pSellerSet | see Suppliers.SellerSet |
Definition at line 245 of file Suppliers.java.
00245 { 00246 int lNumRemainingFirmsToObserve = numFirmsToObserveTable.valueOf(inputSector.getNumFirms()); 00247 00248 // check that the array size is big enough for the needed number of firms 00249 if (sellingFirms.length < lNumRemainingFirmsToObserve + 1) { 00250 sellingFirms = new ISeller[(lNumRemainingFirmsToObserve + 1) * 2]; 00251 } 00252 00253 numFoundFirms = 0; 00254 maxSupply = 0.d ; 00255 costOfTotalStock = 0.d; 00256 00257 // Add first the preferred firms to the list of suppliers provided they have not been 00258 // destructed in the meantime. The preferred firms 00259 // are those with whom business was done in the preceding period. 00260 for (ISeller lSeller : preferredFirms) { 00261 if (inputSector.getFirmList().contains(lSeller) == true && 00262 lSeller.getInventory() > 0) { 00263 addSeller(lSeller); 00264 lNumRemainingFirmsToObserve--; 00265 } 00266 } 00267 00268 // observe other firms until the desired number has been observed. 00269 final Iterator<Firm> iterFirmsToObserved = inputSector.getFirmsWithInventory().iterator(); 00270 while (iterFirmsToObserved.hasNext() && (lNumRemainingFirmsToObserve > 0)) { 00271 final Firm lFirm = iterFirmsToObserved.next(); 00272 addSeller(lFirm); 00273 lNumRemainingFirmsToObserve--; 00274 } 00275 00276 probe.reportFoundSuppliersWithoutImports(); 00277 00278 if (pSellerSet == SellerSet.INCLUDE_IMPORT && 00279 inputSector.getImportExport().getInventory() > 0) { 00280 addSeller(inputSector.getImportExport()); 00281 } 00282 }
void updateSuppliers | ( | SellerSet | pSellerSet | ) | [package] |
Rearrange the list of supppliers and replace suppliers which are too expensive.
pSellerSet | see Suppliers.SellerSet |
Definition at line 289 of file Suppliers.java.
Referenced by ImportExport.trade(), Household.trade(), and Firm.trade().
00289 { 00290 00291 ISeller[] lOldSellingFirms = new ISeller[100]; 00292 ArrayTools.deepCopyFromTo(sellingFirms, lOldSellingFirms); 00293 final int lOldNumFoundFirms= numFoundFirms; 00294 // rearrange the array of selling Firms and update maxSupply, CostOfTotalStock and numFoundFirms. 00295 maxSupply = 0.d ; 00296 costOfTotalStock = 0.d; 00297 numFoundFirms =0; 00298 maxSupply(); 00299 for (int iSeller=0; iSeller<lOldNumFoundFirms; iSeller++) { 00300 final ISeller lSeller= lOldSellingFirms[iSeller]; 00301 if (inputSector.getFirmList().contains(lSeller) == true && lSeller.getBAUSupply()>0) { 00302 addSeller(lSeller); 00303 } 00304 } 00305 00306 updateAvailableSuppliers(); 00307 00308 //if supply price is too expensive, replace the most expensive supplier. 00309 // This requires that there are available suppliers. 00310 00311 if (areAvailableSuppliers()&& numFoundFirms>0){ 00312 ISeller lSupplier =null; 00313 int maxTries= (int) Math.ceil(buyer.getObservedSuppliersQuotient()*availableSuppliers.size()); 00314 int nIter=0; 00315 while ( areAvailableSuppliers()&& canExtraSuppliers() && (nIter<=maxTries) && 00316 getLeastExpensiveAvailableSupplier().getPrice()>sellingFirms[getMostExpensiveSupplier()].getPrice()){ 00317 lSupplier = getLeastExpensiveAvailableSupplier(); 00318 //addExtraSeller(lSupplier); 00319 replaceSeller(getMostExpensiveSupplier(),lSupplier); 00320 nIter++; 00321 } 00322 00323 } 00324 00325 00326 assert(FloatMath.greaterOrApproxZero(maxSupply())); 00327 }
void addSuppliers | ( | double | pDemand, | |
SellerSet | pSellerSet | |||
) | [package] |
Add suppliers in case of rationing,.
pDemand | the demand of the buyer without rationing. | |
pSellerSet | see Suppliers.SellerSet |
Definition at line 336 of file Suppliers.java.
Referenced by ImportExport.trade(), Household.trade(), and Firm.trade().
00336 { 00337 // while rationed, add a supplier. 00338 //This Requires that there are available suppliers and that the suppliers list is not full. 00339 updateAvailableSuppliers(); 00340 while (FloatMath.lowerOrApproxEqual(maxSupply, pDemand) && areAvailableSuppliers() && canExtraSuppliers()){ 00341 addExtraSeller(getLeastExpensiveAvailableSupplier()); 00342 } 00343 probe.reportFoundSuppliersWithoutImports(); 00344 00345 if (pSellerSet == SellerSet.INCLUDE_IMPORT && 00346 inputSector.getImportExport().getInventory() > 0) { 00347 addSeller(inputSector.getImportExport()); 00348 } 00349 assert(FloatMath.greaterOrApproxZero(maxSupply())); 00350 00351 for (int iSupplier=0; iSupplier<numFoundFirms; iSupplier++){ 00352 assert(availableSupply[iSupplier]<=sellingFirms[iSupplier].getBAUSupply()); 00353 00354 } 00355 }
void addSeller | ( | ISeller | pSeller | ) |
Add a Seller of goods of the Sector Suppliers.inputSector which supplies getBAUSupply() to the list of potential suppliers in the trade phase.
pSeller | A potential supplier |
Definition at line 366 of file Suppliers.java.
Referenced by Suppliers.addSuppliers(), Suppliers.findSuppliers(), and Suppliers.updateSuppliers().
00366 { 00367 assert(pSeller.getProductionSector() == inputSector); 00368 sellingFirms[numFoundFirms] = pSeller; 00369 final double lSupply = pSeller.getBAUSupply(); 00370 assert (lSupply>=0); 00371 availableSupply[numFoundFirms]=lSupply; 00372 maxSupply += lSupply; 00373 numFoundFirms++; 00374 maxSupply(); 00375 costOfTotalStock += lSupply * pSeller.getPrice(); 00376 availableSuppliers.remove(pSeller); 00377 }
void addExtraSeller | ( | ISeller | pSeller | ) |
Add a Seller of goods of the Sector Suppliers.inputSector which supplies getExtraSupply() to the list of potential suppliers in the trade phase.
pSeller | A potential supplier |
Definition at line 385 of file Suppliers.java.
Referenced by Suppliers.addSuppliers().
00385 { 00386 assert(pSeller.getProductionSector() == inputSector); 00387 assert(pSeller.getExtraSupply() > 0); 00388 sellingFirms[numFoundFirms] = pSeller; 00389 final double lSupply = pSeller.getExtraSupply(); 00390 assert (lSupply<=pSeller.getInventory()); 00391 availableSupply[numFoundFirms]=lSupply; 00392 assert(availableSupply[numFoundFirms]<=pSeller.getExtraSupply()); 00393 maxSupply += lSupply; 00394 costOfTotalStock += lSupply * pSeller.getPrice(); 00395 availableSuppliers.remove(pSeller); 00396 numFoundFirms++; 00397 }
void replaceSeller | ( | int | pIndex, | |
ISeller | pSeller | |||
) |
In Suppliers.inputSector, replace a seller supplying getBAUSupply() by a new one supplying getExtraSupply().
pIndex | the index of the seller to be replaced | |
pSeller | the seller which replaces the old one |
Definition at line 404 of file Suppliers.java.
Referenced by Suppliers.updateSuppliers().
00404 { 00405 final ISeller lOldSeller= sellingFirms[pIndex]; 00406 final double lOldMaxSupply=maxSupply; 00407 final double lOldSupply = lOldSeller.getBAUSupply(); 00408 assert (lOldSupply==availableSupply[pIndex]); 00409 final double lNewSupply = pSeller.getExtraSupply(); 00410 final double lOldPrice = lOldSeller.getPrice(); 00411 final double lNewPrice = pSeller.getPrice(); 00412 sellingFirms[pIndex] = pSeller; 00413 availableSupply[pIndex]=lNewSupply; 00414 assert(availableSupply[pIndex]<=sellingFirms[pIndex].getInventory()); 00415 maxSupply += lNewSupply-lOldSupply; 00416 costOfTotalStock += lNewSupply*lNewPrice-lOldSupply*lOldPrice; 00417 availableSuppliers.remove(pSeller); 00418 availableSuppliers.add(lOldSeller); 00419 00420 }
double maxSupply | ( | ) | [package] |
Return the total unit of goods that the suppliers can deliver.
The calculation itself happens in Suppliers.findSuppier and Suppliers.buy.
Definition at line 465 of file Suppliers.java.
Referenced by Suppliers.addExtraSeller(), Suppliers.addSeller(), Suppliers.addSuppliers(), Suppliers.averagePrice(), Suppliers.buy(), Suppliers.buyValue(), Suppliers.findSuppliers(), Suppliers.replaceSeller(), and Suppliers.updateSuppliers().
00465 { 00466 double lSum=0; 00467 for(int iIndex=0;iIndex <numFoundFirms; iIndex++){ 00468 lSum+= availableSupply[iIndex]; 00469 } 00470 assert (lSum>=0); 00471 return maxSupply; 00472 }
double costOfTotalStock | ( | ) | [package] |
Return the total cost of the stock that the suppliers can deliver.
The calculation itself happens in Suppliers.updateSuppliers and Suppliers.buy.
Definition at line 481 of file Suppliers.java.
Referenced by Suppliers.addExtraSeller(), Suppliers.addSeller(), Suppliers.averagePrice(), Suppliers.buy(), Suppliers.buyValue(), Suppliers.findSuppliers(), Suppliers.replaceSeller(), and Suppliers.updateSuppliers().
00481 { 00482 return costOfTotalStock; 00483 }
double buy | ( | double | pAmount | ) | [package] |
Buy pAmount of the good produced by the inputSector from the firms in the supplierList.
The stock of the buyer isn't updated here, this must be done explicit in the method that call buy.
pAmount | The amount that should be bought. |
Definition at line 497 of file Suppliers.java.
Referenced by ImportExport.trade(), and Firm.trade().
00497 { 00498 //assert (pAmount >=0); 00499 assert (FloatMath.lowerOrApproxEqual(pAmount, maxSupply())); 00500 double lSumCost = 0d; 00501 00502 int iSupplier; 00503 int nIter=0; 00504 while (!FloatMath.approxZero(pAmount, 1e-10) && 00505 (sellingFirms[iSupplier= getCheapestSupplierWithAvailableSupply()] != null) && nIter<=numFoundFirms) { 00506 ISeller lSupplier= sellingFirms[iSupplier]; 00507 // hacks to prevent rounding errors 00508 double lTradeQuantity = Math.min(maxSupply(),Math.min(pAmount,availableSupply[iSupplier])); 00509 assert(lTradeQuantity>=0); 00510 lSupplier.sell(lTradeQuantity); 00511 availableSupply[iSupplier]-= lTradeQuantity; 00512 maxSupply -= lTradeQuantity; 00513 lSumCost += lTradeQuantity * lSupplier.getPrice(); 00514 pAmount -= lTradeQuantity; 00515 //assert(lTradeQuantity>0); 00516 foundation.getTradeTrace().reportTrade(lTradeQuantity, buyer, lSupplier); 00517 nIter++; 00518 } 00519 00520 costOfTotalStock -= lSumCost; 00521 assert(maxSupply>=0); 00522 00523 return lSumCost; 00524 }
double buyValue | ( | double | pValue | ) | [package] |
Buy for a value of pValue the good produced by the inputSector from the firms in the supplierList.
The stock of the buyer isn't updated here, this must be done explicit in the method that call buy.
pAmount | The value that should be bought. |
Definition at line 538 of file Suppliers.java.
Referenced by Household.trade().
00538 { 00539 assert (FloatMath.greaterOrApproxZero(pValue)); 00540 assert (FloatMath.lowerOrApproxEqual(pValue, costOfTotalStock())); 00541 double lSumAmount = 0d; 00542 double lTax= foundation.getGovernment().getCarbonTaxRate(inputSector.getArrayIndex()); 00543 00544 int iSupplier; 00545 int nIter=0; 00546 while (!FloatMath.approxZero(pValue, 1e-10) && 00547 (sellingFirms[iSupplier= getCheapestSupplierWithAvailableSupply()] != null)&& nIter<=numFoundFirms) { 00548 ISeller lSupplier= sellingFirms[iSupplier]; 00549 double lPrice = (1+lTax)*lSupplier.getPrice(); 00550 final double lTradeValue = Math.min(pValue, availableSupply[iSupplier]*lPrice); 00551 // hacks to prevent rounding errors 00552 final double lTradeQuantity=Math.min(maxSupply(),Math.min(lTradeValue/lPrice,availableSupply[iSupplier])); 00553 lSupplier.sell(lTradeQuantity); 00554 availableSupply[iSupplier]-= lTradeQuantity; 00555 maxSupply -= lTradeQuantity; 00556 lSumAmount+=lTradeQuantity; 00557 pValue -= lTradeValue; 00558 //assert(lTradeQuantity>0); 00559 foundation.getTradeTrace().reportTrade(lTradeQuantity, buyer, lSupplier); 00560 foundation.getGovernment().collectTax(lTax*lTradeQuantity); 00561 nIter++; 00562 } 00563 assert(FloatMath.greaterOrApproxZero(maxSupply)); 00564 00565 return lSumAmount; 00566 }
int getMostExpensiveSupplier | ( | ) | [private] |
Buy pAmount of the good produced by the inputSector from the firms in the supplierList.
The stock of the buyer isn't updated here, this must be done explicit in the method that call buy.
pAmount | The amount that should be bought. |
Definition at line 580 of file Suppliers.java.
Referenced by Suppliers.updateSuppliers().
00580 { 00581 int iMost = 0; 00582 for (int iSupplier = 0; iSupplier < numFoundFirms; iSupplier++) { 00583 final ISeller lSupplier = sellingFirms[iSupplier]; 00584 if (lSupplier.getPrice() > sellingFirms[iMost].getPrice()) { 00585 iMost = iSupplier; 00586 } 00587 } 00588 return iMost; 00589 }
double averagePrice | ( | ) | [package] |
Calculate the average price for which the good is offered by the found suppliers.
The price is weighted by the units of good that the supplier can deliver.
Definition at line 624 of file Suppliers.java.
Referenced by Household.trade().
00624 { 00625 double lTax= foundation.getGovernment().getCarbonTaxRate(inputSector.getArrayIndex()); 00626 if (! FloatMath.lowerOrApproxZero(maxSupply) ) { 00627 return (1+lTax)*costOfTotalStock / maxSupply; 00628 } else { 00629 return inputSector.getStats().getAverageTradePrice(); 00630 } 00631 }
Sector inputSector [private] |
The sector under consideration in the supplier search.
Definition at line 137 of file Suppliers.java.
Referenced by Suppliers.addExtraSeller(), Suppliers.addSeller(), Suppliers.addSuppliers(), Suppliers.averagePrice(), Suppliers.buyValue(), Suppliers.findSuppliers(), and Suppliers.updateSuppliers().
ISeller [] sellingFirms = new ISeller[100] [private] |
The list of firms from the sector Suppliers.inputSector that have a non-empty inventory when findSuppliers is called.
Definition at line 150 of file Suppliers.java.
Referenced by Suppliers.addExtraSeller(), Suppliers.addSeller(), Suppliers.addSuppliers(), Suppliers.buy(), Suppliers.buyValue(), Suppliers.findSuppliers(), Suppliers.getMostExpensiveSupplier(), Suppliers.replaceSeller(), and Suppliers.updateSuppliers().
int numFoundFirms = 0 [private] |
A counter for the number of selling firms already found.
Definition at line 167 of file Suppliers.java.
Referenced by Suppliers.addExtraSeller(), Suppliers.addSeller(), Suppliers.addSuppliers(), Suppliers.findSuppliers(), and Suppliers.updateSuppliers().
double firmsToObserveQuotient [private] |
The number of selling firms to be observed is calculated by multiplying the number of firms in the supplying sector with this quotient.
Definition at line 175 of file Suppliers.java.
The agent that is observing the firms.
Definition at line 181 of file Suppliers.java.
Referenced by Suppliers.buy(), Suppliers.buyValue(), and Suppliers.updateSuppliers().
double maxSupply = 0 [private] |
The sum of goods of all firms in the Suppliers.sellingFirms array.
Definition at line 200 of file Suppliers.java.
Referenced by ImportExport.trade(), and Firm.trade().
double costOfTotalStock = 0 [private] |
The money that would be needed for buying the inventory of all firms in the Suppliers.sellingFirms array.
Definition at line 210 of file Suppliers.java.
RandomGenerator random = null [private] |
The random generator.
Definition at line 215 of file Suppliers.java.
Referenced by Suppliers.init().