7 #include "../safeguards.h"
9 typedef std::queue<NodeID> NodeList;
60 return std::max(from.
Supply() * std::max(1U, to.
Supply()) * this->mod_size / 100 / this->demand_per_node, 1U);
72 return (to.
Supply() == 0 || to.UndeliveredSupply() > 0) && to.
Demand() > 0;
132 if (job[from_id].Demand() > 0) {
133 uint demand_back = demand_forw * this->
mod_size / 100;
134 uint undelivered = job[to_id].UndeliveredSupply();
135 if (demand_back > undelivered) {
136 demand_back = undelivered;
137 demand_forw = std::max(1U, demand_back * 100 / this->
mod_size);
155 job[from_id].DeliverSupply(to_id, demand_forw);
163 template<
class Tscaler>
168 uint num_supplies = 0;
169 uint num_demands = 0;
171 for (NodeID node = 0; node < job.
Size(); node++) {
172 scaler.AddNode(job[node]);
173 if (job[node].Supply() > 0) {
177 if (job[node].Demand() > 0) {
183 if (num_supplies == 0 || num_demands == 0)
return;
188 scaler.SetDemandPerNode(num_demands);
191 while (!supplies.empty() && !demands.empty()) {
192 NodeID from_id = supplies.front();
195 for (uint i = 0; i < num_demands; ++i) {
196 assert(!demands.empty());
197 NodeID to_id = demands.front();
199 if (from_id == to_id) {
201 if (demands.empty() && supplies.empty())
return;
207 int32 supply = scaler.EffectiveSupply(job[from_id], job[to_id]);
221 uint demand_forw = 0;
222 if (divisor <= supply) {
226 demand_forw = supply / divisor;
227 }
else if (++chance > this->
accuracy * num_demands * num_supplies) {
233 demand_forw = std::min(demand_forw, job[from_id].UndeliveredSupply());
235 scaler.SetDemands(job, from_id, to_id, demand_forw);
237 if (scaler.HasDemandLeft(job[to_id])) {
243 if (job[from_id].UndeliveredSupply() == 0)
break;
246 if (job[from_id].UndeliveredSupply() != 0) {
247 supplies.push(from_id);
269 this->
mod_dist = 100 + over100 * over100;
272 switch (
settings.GetDistributionType(cargo)) {