本文整理汇总了C++中Agent::getDeviceLifetime方法的典型用法代码示例。如果您正苦于以下问题:C++ Agent::getDeviceLifetime方法的具体用法?C++ Agent::getDeviceLifetime怎么用?C++ Agent::getDeviceLifetime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Agent
的用法示例。
在下文中一共展示了Agent::getDeviceLifetime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: highOrderNeeded
/**
* \param an agent
* \return a pair of (timeNeeded, necessaryRes) where the necessary time and resources to make the device and its components, if the agent is not able to buy any components.
*/
pair<double, vector<int> > Device::worstCaseConstruction(Agent &agent)
{
/*
* If the memory of this calculation that the agent has is valid, return
* the value in memory
*/
if (agent.devProp[type][use].worstCaseConstructionMemoryValid) {
return agent.devProp[type][use].worstCaseConstructionMemory;
} else {
/*
* highOrderNeeded will be a list of the number of typeToCheck
* devices needed for the corresponding resId
*/
vector<int> highOrderNeeded(glob.NUM_RESOURCES, 0);
/*
* Begin by requiring one device of the type that is currently under
* consideration
*/
highOrderNeeded[use] = 1;
/* typeToCheck begins as the type of device under consideration */
device_name_t typeToCheck = type;
/* compType is the component type of typeToCheck */
device_name_t compType = componentType;
/*
* timeNeeded will be the total, worst case time for this device and
* its components.
*/
double timeNeeded = 0.0;
if (devDevice != NO_DEVICE &&
agent.devProp[devDevice][use].deviceHeld > 0.0) {
timeNeeded = agent.deviceEffortCalc(use, type) / agent.getDeviceFactor(devDevice);
} else {
timeNeeded = agent.deviceEffortCalc(use, type);
}
/*
* Loop through so that typeToCheck and compType become lower and
* lower order device types; stop when there are no more lower order
* devices to consider.
*/
while (compType != NO_DEVICE) {
/*
* Given the number of typeToCheck devices in highOrderNeeded,
* compNeeded is the number of compType devices needed for each
* corresponding resId.
*/
vector<int> compNeeded(glob.NUM_RESOURCES, 0);
/*
* Begin by simply adding the components of devices in
* highOrderNeeded
*/
for (int resId = 0; resId < glob.NUM_RESOURCES; resId++) {
if (highOrderNeeded[resId] > 0) {
for (int i = 0; i < (int) glob.discoveredDevices[typeToCheck][resId]->components.size(); i++) {
int compId = glob.discoveredDevices[typeToCheck][resId]->components[i];
compNeeded[compId] += highOrderNeeded[resId];
}
}
}
for (int resId = 0; resId < glob.NUM_RESOURCES; resId++) {
if (compNeeded[resId] > 0) {
/*
* Remove devices from compNeeded if enough of the
* device is held by the agent; the number removed is
* the number of devices held (i.e. lifetime held
* divided by lifetime per device)
*/
compNeeded[resId] = max(0, compNeeded[resId] -
(int(agent.devProp[compType][resId].deviceHeld)
/ int(agent.getDeviceLifetime(compType))));
}
}
/*
* The time needed to make each of these components is added to
* timeNeeded
*/
for (int resId = 0; resId < glob.NUM_RESOURCES; resId++) {
if (compNeeded[resId] > 0) {
device_name_t devDevice = glob.discoveredDevices[compType][resId]->devDevice;
/*
* If the device-making device is not invented or if
* the agent doesn't hold any, the devDeviceFactor
* is 1 (i.e. no effect on production)
*/
double devDeviceFactor = 1.0;
if (devDevice != NO_DEVICE &&
agent.devProp[devDevice][resId].deviceHeld > 0.0) {
devDeviceFactor = agent.getDeviceFactor(devDevice);
}
for (int i = 0; i < compNeeded[resId]; i++) {
timeNeeded += agent.tempDeviceEffortCalc(resId, compType, i) / devDeviceFactor;
}
}
//.........这里部分代码省略.........