Since we have added resource constraints as an additional factor in our decision process, let us create a custom function to calculate the gold cost for a given battle plan:
> #custom function that calculates the gold cost of a battle > #cost formula: travel cost + (provision cost + equipment cost) * battle duration > functionGoldCost <- function(ShuSoldiers, distance, duration) + { + ShuSoldiers * ((distance / 100) + 2 * (duration / 30)) + }
> #what is the predicted cost of an attack by 25,000 Shu soldiers that takes place 100 miles away and lasts for 90 days? > functionGoldCost(25000, 100, 90) [1] 175000
We now have a way to calculate the gold cost of our potential strategies. Alternatively, you could also choose to create functions solving for other combat constraints, such as soldiers, distance, or duration.
We created a custom function that tells us how much gold we would need to execute our plans when the number of Shu soldiers, the distance to the attack site, and the proposed duration of the battle are known.
The formula that we used in our gold cost function may seem unfamiliar. This is because it was coded in its simplest, and therefore easiest to read, form. The expanded formula for calculating our gold cost is detailed as follows:
ShuSoldiers * distance / 100 + ShuSoldiers * provision cost * duration + ShuSoldiers * equipment cost * duration
Once simplified, we are left with the formula used in our gold cost function:
ShuSoldiers * ((distance / 100) + 2 * (duration / 30))
The ShuSoldiers
term has been extracted and placed at the front of the equation. The distance
is divided by 100, because the cost of moving one soldier is one gold per 100 miles. The duration
is multiplied by two and divided by 30, because the cost of provisions and equipment are both one gold per soldier per 30 days of battle. In the end, we have the same output as with our expanded formula, but using much less space.
a. Considering logistics helps us to account for resource constraints.
b. Considering logistics helps us to identify a realistic set of opportunities.
c. Predicted outcomes are not always logistically viable.
d. Predicted outcomes present the most logistically sound course of action.
Create a custom function that tells us how many miles our army can travel given the proposed amount of gold, number of soldiers, and duration of the attack. Save it into a variable named functionMaxDistance
. This function will prove useful in assessing the viability of the strategies predicted by our regression models.