WATER: Implementation

Die Implementation eines Computermodells sollte schrittweise stattfinden, da der Implementationsvorgang das vollständige und tiefe Verständnis der Modellstruktur erst ermöglicht. Selbstverständlich sind Kenntnisse der Programmiersprache notwendig, um den Quellcode eines Modells zu erfassen, dies betrifft im Folgenden die Programiersprache JAVA, und ebenso das Framework VSEit.

Class Water supplier

class WaterSupplier extends Object
{
 Model world;

 double averageCost;    // Costs per cbm water in the last year
 double price;                  // Price per cbm water
 double saldo;                 // Surplus or loss in the last year
 double quantity;           // Water demand in the last year
 double account;           // account with interest
 String type;                   // enterprise type
 int i = 0;                          // index of periods
 double snew;                // current saldo
 double sold;                  // saldo in the last period
 double p;                       // price step
 double q;                       // price step reduction factor
 

 WaterSupplier(Model w, double ip, String enterpriseType, double pCh, double qRed )
 {
  super();
  world = w;
  price = ip;
  type = enterpriseType;
  p = pCh;
  q = qRed;

 }

 double cost(double q)       //calculate costs for specific demand q
 {
  double c = world.getDoubleParameter("costLevel");
  double b = world.getDoubleParameter("returnScale");

  return c * Math.pow(q, b);        //costs for water demand in the last period
 }

 void determineNewPrice()          // lay down the method for calculate the new price, depending on the type of enterprise
 {
  if (type == "public"){
   this.determineNewPricePublic();
  }

  else {                                             //type == "private"
   this.determineNewPricePrivate();
  }
 }

 void determineNewPricePublic()
 {
  quantity = world.waterDemand(price);                  //get new water demand with current water price
  averageCost = this.cost(quantity) / quantity;      //average costs for current water demand
  saldo = (price-averageCost)*quantity;
  account = world.financialInstitution(saldo);
  price = averageCost;                                                //new price = current average costs

   double limit = world.getDoubleParameter("maxPrice");           //avoid a water price wich is higher than the water price limit
   if(limit != 0)
    price = Math.min(price,limit);
 }
 

 void determineNewPricePrivate()
 {
  quantity = world.waterDemand(price);                      //get new water demand with current water price
  averageCost = this.cost(quantity) / quantity;          //average costs for current water demand
  saldo = (price-averageCost)*quantity;
  snew = saldo;                                                                // save new saldo

  if (i == 0){                                                                       // first period in private buisiness
   price = price - p;                                                           // first price related to level of waterdemand
  }

  else if (i == 1){
   if (snew < sold){                                                          // saldo in the current period is smaller than saldo in the last period)
   p = -p;                                                                           // direction of price step depends on saldo proportion
   price = price - p;                                                           // new price
   }

   else {                                                                              // snew > sold (saldo in the current period is larger than saldo in the last period)
   price = price - p;                                                           // new price
   }
  }

  else{                                                                                // following periods
   if (snew < sold){                                                          // saldo in the current period is smaller than saldo in the last period)
    p = - q * p;                                                                   // change of the size of price step
    price = price - p;                                                          // new price
   }

   else                                                                                // snew > sold (saldo in the current period is larger than saldo in the last period)
   price = price - p;                                                           // new price
  }

   double limit = world.getDoubleParameter("maxPrice");     // avoid a water price wich is higher than the water price limit
   if(limit != 0)
    price = Math.min(price,limit);
 

  sold = snew;                                                                 // save saldo for following period as sold (saldo in the last period)
  i++;

 }

......

}
 
 

Class Water consumer

class WaterConsumer extends Object
{
 Model world;
 double tDemand;

 WaterConsumer(Model w)
 {
  super();
  world = w;
  }
 

 double demand(double price)                                     //consumer determine new demand with current waterprice
 {
    double x = world.getDoubleParameter("waterSave");
    double a = world.getDoubleParameter("elasticity");
    double avar = world.getDoubleParameter("elasticityVar");
    double dvar = world.getDoubleParameter("demandVar");
    double e = world.getDoubleParameter("demandLevelTech");
    double b = world.getDoubleParameter("elasticityTech");
    double h = world.getDoubleParameter("minWater");
    double d = world.getDoubleParameter("demandLevel");

    d = d - d * ((x/100)*(this.TUse()/(e)));                     //new demandlevel with current technology use

    double z = -world.nextNormal(a,avar)*price + world.nextNormal(d, dvar);         //new waterdemand with current waterprice

   if (z < h)                                                                          //avoid negative waterdemand
   z = h;
   else
   z = z;

  return z;                                                                         //return new waterdemand to world
   }

 double techUse(double techPrice)                            //consumer determine new demand with current technologyprice
 {
    double b = world.getDoubleParameter("elasticityTech");
    double e = world.getDoubleParameter("demandLevelTech");
    tDemand = -b * techPrice + e;                                 //new technologydemand with current technologyprice

     if (tDemand < 0)                                                        //avoid negative technologydemand
     tDemand = 0;
     else
     tDemand = tDemand;

    return tDemand;                                                        //return new technologydemand to world
   }

   double TUse()
   {
    return tDemand;                                                       //return new technologydemand to consumer for determine new waterdemand
   }

}
 

Class Technology

class Technology extends Object
{
    Model world;

    double techPrice;
    double time;
    double trendPrice;
    double techQuantity;

    Technology(Model w, double itp, String tp)
    {
        super();
        world = w;
        techPrice = itp;
        time = 1;

        if (tp == "large reduction"){
            trendPrice = 0.01;                                             //price cut per time step for 'large reduction'
        }

        else if (tp == "medium reduction"){
            trendPrice = 0.001;                                           //price cut per time step for 'medium reduction'
        }

        else {                                                                      //tp == "small reduction"
            trendPrice = 0.0001;                                         //price cut per time step for 'small reduction'
        }
    }

 void determineNewTechPrice()
 {
        techPrice = techPrice/time;                                 //determine new technology price in current time
        time = time + trendPrice;                                     //price cut for the next timestep
        techQuantity = world.techUse(techPrice);      //get new technology demand with new technology price
    }

    double getTechPrice() {return techPrice;}
    double getTechUse() {return techQuantity;}
}

zurück zu: