Time for action - incorporating resource constraints into predictions

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:

  1. Define a custom function that calculates the gold cost of a battle when its distance, duration, and number of Shu soldiers engaged are known:
    > #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))
    + }
    
  2. Test the function:
    > #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.

What just happened?

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.

Gold cost function explanation

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.

Pop quiz

  1. Which of the following is not a reason to carefully consider the logistics of predicted outcomes?

    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.

Have a go hero

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.8.90