Ejemplo n.º 1
0
 private void trade(int x, Human other) {
   // Determine how low and high the agents are in the given good (not Giffen good)
   double deficit = minThreshold[x] - commoditiesHeld[x];
   double surplus = other.commoditiesHeld[x] - other.minThreshold[x];
   // Sell only if the buyer is willing to pay more than the seller wants???
   // if(expPrice[x]>other.expPrice[x]){//SELLER HAS MONOPOLISTIC CONTROL!!! MAYDAY!
   // Haggle to the price being the average of the two expecteds
   double price = (expPrice[x] + other.expPrice[x]) / 2;
   double diff = price - expPrice[x];
   // Bring both agents' expectations a tenth of the way to the average
   diff /= 10;
   expPrice[x] += diff;
   diff = price - other.expPrice[x];
   diff /= 10;
   other.expPrice[x] += diff;
   // Decide the amount to buy so as not to bring buyer above or seller below need level
   if (deficit > surplus) {
     money -= surplus * price;
     other.money += surplus * price;
     other.commoditiesHeld[x] -= surplus;
     commoditiesHeld[x] += surplus;
   } else {
     money -= deficit * price;
     other.money += deficit * price;
     other.commoditiesHeld[x] -= deficit;
     commoditiesHeld[x] += deficit;
   }
   // Increment model-wide trades
   Model.instance().incrementTrades();
   /*}else{
   other.expPrice[x] = other.expPrice[x]-((other.expPrice[x]-expPrice[x])/10);
   expPrice[x] = expPrice[x]+((other.expPrice[x]-expPrice[x])/10);
   }*/
 }
Ejemplo n.º 2
0
  private void selectProducer(Human seller, int good) {
    double price = seller.expPrice[good];
    double quantity = budgetExp[good] / price;
    double otherQuantity = seller.budgetExp[good] / price; // seller.chokeQuant[good];
    String message;
    /*double quantity = chokeQuant[good];
      double otherQuantity = seller.chokeQuant[good];
    //How much is the buyer willing to buy at the price
    for(int i=0; i<Commodity.NUM_COMM; i++){
    if(i!=good){
    quantity -= demandSlope[i]*expPrice[i];
    }else{
    quantity -= demandSlope[good]*price;
    }
    }*/
    /*for(int k=0; k<Commodity.NUM_COMM; k++){
    otherQuantity -= seller.demandSlope[k]*seller.expPrice[k];
    }*/
    double firstQuantity = quantity;
    if (otherQuantity > (seller.commoditiesHeld[good] - quantity)) {
      quantity = (seller.commoditiesHeld[good] - quantity);
      // Remove seller from producer arrayList
      // cph Seller sold inventory, raises price to reflect scarcity of his good
      seller.expPrice[good] *= changeProp;
      if (good == GOOD) {
        message =
            "Producer of good "
                + Integer.toString(GOOD)
                + " ran out, price rises to "
                + Double.toString(seller.expPrice[good])
                + " wanted to hold quantity "
                + Double.toString(quantity)
                + " not "
                + Double.toString(firstQuantity);
        debug(message, PRICE);
      }
      Model.instance().removeFromProducers(seller.producedCommodity, seller);
      debug("removing", false);
    }
    double diff = price - expPrice[good];
    diff /= 10;
    double tempUnDiff = expPrice[good];
    // expPrice[good]+=diff;
    if (good == 2) {
      message =
          "2 price changed from "
              + Double.toString(tempUnDiff)
              + " to "
              + Double.toString(expPrice[good]);
      debug(message, TRADE);
      message = "2 price changed by " + Double.toString(diff);
      debug(message, TRADE);
      // System.out.printf("2 price changed from %f to %f\n", tempUnDiff, expPrice[good]);
      // System.out.printf("2 price changed by %f\n", diff);
    }
    // If they bought, raise seller's price
    if (quantity > 0) { // && money >= price*quantity){
      // System.out.printf("We bought %f at %f!\n",quantity, price);
      seller.commoditiesHeld[good] -= quantity;
      commoditiesHeld[good] += quantity;

      budgetExp[good] -= quantity * price;
      seller.money += quantity * price;
      money -= quantity * price;

      Commodity.getCommNum(good).reportSale(quantity);
      totalSpent += quantity * price;
      // seller.expPrice[good]*=1.01;
    } else {
      // System.out.printf("We didn't buy at %f!\n", price);
    }
  }