Production Efficiency
For each item, we calculate the profit per second to find the most efficient production path.
Raw Materials
For raw materials (items produced directly from facilities like Farmland):
\[ \text{Profit/sec} = \frac{(\text{yield} \times \text{sell_price}) - \text{cost}}{t_{\text{effective}}} \]
Where effective time accounts for parallel production with multiple facilities:
\[ t_{\text{effective}} = \frac{t_{\text{production}}}{n_{\text{facilities}}} \]
Processed Items
For processed items that require raw materials, production is limited by the bottleneck:
\[ \text{Gathering Rate} = \frac{n_{\text{gatherers}} \times \text{yield}}{t_{\text{gather}} \times \text{required_amount}} \]
\[ \text{Processing Rate} = \frac{n_{\text{processors}}}{t_{\text{process}}} \]
\[ \text{Effective Rate} = \min(\text{Gathering Rate}, \text{Processing Rate}) \]
Cross-Facility Parallel Production
When enabled, multiple independent production chains run simultaneously:
\[ \text{Total Profit/sec} = \sum_{i=1}^{k} \text{profit_rate}_i \]
Chains are selected greedily by efficiency, skipping any that conflict with already-selected facilities.
Optimal Facility Allocation
When a recipe requires multiple raw materials from the same facility type (e.g., lavender + rose from Farmland), we optimize how to split facilities.
The Problem
Minimize the maximum completion time across all materials:
\[ \min \max_i \left( \left\lceil \frac{B_i}{f_i} \right\rceil \times t_i \right) \quad \text{s.t.} \quad \sum_i f_i = F \]
Where:
- \(B_i\) = batches needed for material \(i\)
- \(f_i\) = facilities allocated to material \(i\)
- \(t_i\) = production time for material \(i\)
- \(F\) = total facilities available
The Algorithm
We use binary search on candidate completion times:
- Generate candidates: For each material, possible completion times are \(\lceil B_i / k \rceil \cdot t_i\) for \(k = 1, 2, \ldots\). Using the divisor counting trick, there are only \(O(\sqrt{B_i})\) distinct values.
- Binary search: For candidate time \(T\), check feasibility:
- Max rounds for material \(i\): \(r_i = \lfloor T / t_i \rfloor\)
- Min facilities needed: \(\lceil B_i / r_i \rceil\)
- Feasible if \(\sum_i \lceil B_i / r_i \rceil \leq F\)
- Allocate: Assign minimum facilities, then greedily distribute remaining.
Example
Producing dried_flowers (requires lavender + rose) with 20 Farmlands:
| Material | Batches | Time |
| lavender | 666 | 5400s |
| rose | 666 | 8100s |
Naive split (10 each):
\[ t = \max\left(\lceil 666/10 \rceil \times 5400, \lceil 666/10 \rceil \times 8100\right) = 542700s \]
Optimal split (8 lavender, 12 rose):
\[ t = \max\left(\lceil 666/8 \rceil \times 5400, \lceil 666/12 \rceil \times 8100\right) = 453600s \]
The optimal allocation saves ~25 hours by giving more facilities to the slower material.
Complexity
| Operation | Complexity |
| Efficiency calculation | \(O(n \cdot m^2)\) |
| Parallel mode selection | \(O(n \log n + n \cdot f)\) |
| Facility allocation | \(O(M \cdot \sqrt{B} \cdot \log(M\sqrt{B}))\) |
Where \(n\) = items, \(m\) = chain depth, \(f\) = facilities per chain, \(M\) = materials in recipe, \(B\) = max batches.