Пример #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);
   }*/
 }
Пример #2
0
 private void buyFrom(Human other) {
   // Show that the agents have engaged in another trade
   incrementTrades();
   other.incrementTrades();
   // Check each commodity for trading value
   for (int i = 0; i < Commodity.NUM_COMM; i++) {
     // If the buyer is low in the commodity...
     if (checkStatus(i) == CommodityStatus.DEFICIENT) {
       // And the seller is satisfied...
       if (other.checkStatus(i) == CommodityStatus.SATISFIED) {
         // Let the trades begin!
         trade(i, other);
       } else {
         // If the seller is also low, the good is scarce and price expectations rise
         expPrice[i] *= 1.01;
         other.expPrice[i] *= 1.01;
       }
       // If both agents are satisfied, the good is not as scarce and price expectations fall
     } else if (other.checkStatus(i) == CommodityStatus.SATISFIED) {
       expPrice[i] *= .99;
       other.expPrice[i] *= .99;
     }
   }
 }
Пример #3
0
 /*Give an even portion of the agent's goods to all the children*/
 private void omniBequeath(Human man) {
   if (man.children.size() == 0) {
     // std::cout<<"Childless ";
     /*TODO remove holdings from model*/
   } else {
     if (man.children.size() > 1) {
       Model.instance().addToWealthRedistributed(man.getWealth());
       Model.instance().incrementOmniEvent();
     }
     for (int i = 0; i < man.children.size(); i++) {
       for (int j = 0; j < Commodity.NUM_COMM; j++) {
         double progeny = man.children.size();
         man.children.get(i).commoditiesHeld[j] += man.commoditiesHeld[j] / progeny;
         man.children.get(i).money += man.money / progeny;
       }
     }
   }
 }
Пример #4
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);
    }
  }