/** * \param agent * \return The estimated construction time of the device and its components, if the agent is able to buy some components */ double Device::expectedConstructionTime(Agent &agent) { /* * if the agent believes that it can buy the device, the expected time * to build the device is 0. */ if (agent.canBuy(*this).first) { return 0.0; } /* * If the agent does not believe it can buy the device, it calculates * the time required to make the device based on its experience and * whether or not it has a device-making device, then it recursively * adds the expected construction time of each of the components */ device_name_t bestDevDevice = agent.bestDevDevice(type, use); double time; if (bestDevDevice != NO_DEVICE) { time = agent.deviceEffortCalc(use, type) / agent.getDeviceFactor(bestDevDevice); } else { time = agent.deviceEffortCalc(use, type); } for (int i = 0; i < (int) components.size(); i++) { int comp = components[i]; time += glob.discoveredDevices[componentType][comp]->expectedConstructionTime(agent); } return time; }
/** * \param agent * \return the sum of the costs of the components to the agent */ double Device::costs(Agent &agent) { if (agent.devProp[type][use].costOfDeviceMemoryValid) { return agent.devProp[type][use].costOfDeviceMemory; } else { /* canBuy returns a boolean and a double */ pair<bool, double> buy = agent.canBuy(*this); /* * canBuy is the boolean; it indicates whether or not the agent * believes it is able to buy the device */ bool canBuy = buy.first; /* * If the agent believes it is able to buy the device, the price (in * utils) that it expects to pay is avgPrice * So, if the agent believes it is able to buy the device, the cost * is avgPrice. */ double avgPrice = buy.second; if (canBuy) { return avgPrice; /* * If the agent does not believe that it can buy the device, it * calculates the cost of the device as the time required to make * this device plus the cost of all the components of this device * (so the cost function gets called recursively on lower and lower * order devices) */ } else { /* * First the agent calculates the time required to make the * device based on the agent's experience and whether or not it * has a device-making device */ double time; device_name_t bestDevDevice = agent.bestDevDevice(type, use); if (bestDevDevice != NO_DEVICE) { time = agent.deviceEffortCalc(use, type) / agent.getDeviceFactor(bestDevDevice); } else { time = agent.deviceEffortCalc(use, type); } /* * The initial cost is the required time multiplied by the gain * per minute that the agent was getting at the end of the last * work day */ double cost = time * agent.endDayGPM; /* * Then, the agent adds the cost of each of the components of * this device. */ for (int i = 0; i < (int) components.size(); i++) { int comp = components[i]; cost += glob.discoveredDevices[componentType][comp]->costs(agent); } agent.devProp[type][use].costOfDeviceMemory = cost; agent.devProp[type][use].costOfDeviceMemoryValid = true; return cost; } } }