0

I am trying to resolve the following problem.

Given the following:
resources: food, wood, stone, gold
units: peon(requirements: 50 food, town hall, 3 turns to make) which can produce: 10 amount of any resource or 3 building points
       warrior(requirements: 30 food, 20 wood, 4 turns to make, barracks)
       archer(requirements: 30 wood, 25 gold, archery, 3 turns to make)
buildings: town hall(requirements: 500 food, 500 points, 20 building points) required to produce peons, only one peon can be produced at a time
           barracks: 100 wood, 50 stone, 10 building points, required to produce warriors
           archery: 200 wood, 30 gold, 12 building points, at least one barracks, required to produce archers
and the following: starting resources, buildings, units and their quantities
                   final resources, buildings, units and their quantities
output: the minimum required turns to get from starting quantities to final quantities of resources, buildings and units
notes: you start with at least one town hall
       what's the point of having multiple town halls: they can produce peons faster

Now, my first approach was to resolve this problem using an heuristic approach, by selecting the most expensive resource/building/unit from the final state and determine what do I need in order to get to that quantity.

And my question is: Is there any non-heuristic approach in resolving this problem/this types problems.

Zoltan Ersek
  • 755
  • 9
  • 28

3 Answers3

1

You could perform a breath first search in the search-tree of all possible moves.

This might take a long time, but guarantees to find the optimal solution.
wikipedia: breath first search

A A*-search can be much faster, but you need to find a heuristic which never underestimates the cost of the remaining (unknown) part of the solution.
wikipedia: A*-search

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
1

Well, you can simplify the problem with a little analysis...

warriors and archers are given no value in the problem as posed, so you'd never spend resources creating them, and therefore have no need for barracks or archery buildings

You're left with:

  • units: peon(requirements: 50 food, town hall, 3 turns to make) which can produce: 10 amount of any resource or 3 building points

  • buildings: town hall(requirements: 500 food, 500 points, 20 building points) required to produce peons, only one peon can be produced at a time

You can then evaluate the number of turns needed if you use only existing peon and town halls, working away until you have the required resources.

If creating more town halls will improve on that, you obviously would want to start creating the town hall as early as possible. So, speculatively analyse the impact of doing so and compare it to the earlier result. If the building helped, do similar analysis to decide whether to start yet another building as each completes....

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252
0

It seems like the only decision is whether to build extra buildings not needed in the final result. I think it could be done using a cost benefit approach. E.g. building extra town hall, has a known cost, benefit depends on how long it is operational. I think it is OK to use heuristics, general solutions to optimisation problems are NP hard.

Anton
  • 39
  • 3