예제 #1
0
 // This constructor is called for new children
 public Human(Human progenitor) {
   mode = LifeStage.EARNING;
   parent = progenitor;
   myId = nextAgentNum++;
   producedCommodity = Model.instance().generateMake(this);
   residentCommunity = parent.residentCommunity;
   age = 0;
   money = 100;
   children = new ArrayList<Human>();
   minThreshold = new double[Commodity.NUM_COMM]; // Between 0 and 5
   commoditiesHeld = new double[Commodity.NUM_COMM];
   timesTraded = 0;
   for (int i = 0; i < Commodity.NUM_COMM; i++) {
     minThreshold[i] = Model.instance().generateNeedCommodityThreshold();
     while (minThreshold[i] < Commodity.getCommNum(i).getAmtCons()) {
       minThreshold[i] = Model.instance().generateNeedCommodityThreshold();
     }
     Commodity.getCommNum(i).incNeed(minThreshold[i]);
     expPrice[i] = Model.instance().generateExpPrice();
     commoditiesHeld[i] = 0;
   }
   allNeeds = 0;
   for (int i = 0; i < Commodity.NUM_COMM; i++) {
     allNeeds += minThreshold[i];
   }
   amountProduced = Model.instance().generateAmountProduced();
   Commodity.getCommNum(producedCommodity).incMakerNum(amountProduced);
   parent.children.add(this);
   Model.instance().addToActors(this);
   Model.instance().addToCommunity(residentCommunity, this);
 }
예제 #2
0
  // Constructors & destructors
  // --------------------------------------------------------------------------
  // This constructor is called for initial agents
  public Human() {
    myId = nextAgentNum++;
    mode = LifeStage.EARNING;
    /*if (myId == 0 || myId == 1) {
    producedCommodity = myId;
    } else {*/
    producedCommodity = Model.instance().generateMake(this);
    // }
    residentCommunity = Model.instance().generateCommunity(this);
    age = 0; // Model.instance().generateAge();
    money = Model.MONEY;
    children = new ArrayList<Human>();
    minThreshold = new double[Commodity.NUM_COMM]; // Between 0 and 5
    commoditiesHeld = new double[Commodity.NUM_COMM];
    expPrice = new double[Commodity.NUM_COMM];
    chokeQuant = new double[Commodity.NUM_COMM];
    demandSlope = new double[Commodity.NUM_COMM];
    budget = new double[Commodity.NUM_COMM];

    // New trade variables
    alpha = new double[Commodity.NUM_COMM];
    beta = new double[Commodity.NUM_COMM];
    goodUtils = new double[Commodity.NUM_COMM];
    utilsDollar = new double[Commodity.NUM_COMM];
    budgetExp = new double[Commodity.NUM_COMM];

    timesTraded = 0;
    for (int i = 0; i < Commodity.NUM_COMM; i++) {
      minThreshold[i] =
          Commodity.getCommNum(i)
              .getAmtCons(); // Model.instance().generateNeedCommodityThreshold();
      /* while( minThreshold[i]< Commodity.getCommNum(i).getAmtCons()) {
      minThreshold[i]=Model.instance().generateNeedCommodityThreshold();
      }*/
      Commodity.getCommNum(i).incNeed(minThreshold[i]);
      expPrice[i] = Model.instance().generateExpPrice();
      chokeQuant[i] = Model.instance().generateChokeQuant();
      demandSlope[i] = Model.instance().generateDemandSlope();
      alpha[i] = Model.instance().generateAlpha();
      beta[i] = Model.instance().generateBeta();
      commoditiesHeld[i] = 0;
    }
    allNeeds = 0;
    for (int i = 0; i < Commodity.NUM_COMM; i++) {
      allNeeds += minThreshold[i];
    }
    amountProduced = Model.instance().generateAmountProduced();
    totalAmountProduced += amountProduced;
    Commodity.getCommNum(producedCommodity).incMakerNum(amountProduced);
    Model.instance().addToActors(this);
    // Model.instance().addToProducers(producedCommodity, this);
  }
예제 #3
0
  public void earnIncome() {
    // If they didn't empty their inventory, lower price
    // Model.instance().showNumOfProducers();
    String message;
    if (Model.instance().findProducer(producedCommodity, this) && Model.instance().getTick() > 1) {
      // cph Decrease price by changeProp to represent unsold inventory
      expPrice[producedCommodity] /= changeProp;
      if (producedCommodity == GOOD) {
        message =
            "Due to surplus inventory, price of "
                + Integer.toString(GOOD)
                + " falls to "
                + Double.toString(expPrice[producedCommodity]);
        debug(message, PRICE);
      }
    }
    /*if((producedCommodity != 5) && (Model.instance().getNumProducers(producedCommodity)>15)){
    producedCommodity = 5;
    }*/
    if (Model.instance().generateSwitch() < Model.SWITCH_PROZ && Model.instance().getTick() > 1) {
      // Remove from current production arrayList
      int com = 0;
      double max = 0;
      for (int i = 0; i < Commodity.NUM_COMM; i++) {
        if (expPrice[i] > max) {
          com = i;
          max = expPrice[i];
        }
      }
      Model.instance().removeFromProducers(producedCommodity, this);
      producedCommodity = com;
    }
    if (Model.instance().findProducer(producedCommodity, this)) {

    } else {
      // Add to new production arrayList
      Model.instance().addToProducers(producedCommodity, this);
    }

    if (producedCommodity == 0) {
      // System.out.println("I produce A!");
    } else {
      // System.out.println("I produce something else!");
    }
    // if(age > 3 && producedCommodity == 1){

    // }else{
    commoditiesHeld[producedCommodity] += amountProduced; // Units?
    Commodity.getCommNum(producedCommodity).produce(amountProduced);
    totalMoney += money;
    makeBudget();
    // }
  }
예제 #4
0
 // Remove half of every commodity and send that info to the commodity
 public void consume() {
   for (int i = 0; i < Commodity.NUM_COMM; i++) {
     // double prop = commoditiesHeld[i]/2;
     double prop = commoditiesHeld[i];
     // double prop = 10;
     Commodity.getCommNum(i).consumeProp(prop);
     commoditiesHeld[i] -= prop;
     // commoditiesHeld[i]-=10;
     /*if(commoditiesHeld[i]-Commodity.getCommNum(i).getAmtCons()>=0) {
       commoditiesHeld[i]-=Commodity.getCommNum(i).getAmtCons();
       Commodity.getCommNum(i).consume();
       } else {
       Commodity.getCommNum(i).consFail(commoditiesHeld[i]);
       commoditiesHeld[i]=0;
     //considerDeath();
     }*/
   }
 }
예제 #5
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);
    }
  }