From 7a0b2bff188e986fb970cc13790de3423ebd93ee Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 29 Apr 2014 18:21:49 +0000 Subject: [PATCH] (svn r26542) [1.4] -Backport from trunk: - Change: Remove demand calculation based on tiles (r26484) - Fix: Allow single-vehicle consists to station-refit in a meaningful way (r26483) --- src/economy.cpp | 9 ++++++-- src/linkgraph/demands.cpp | 47 +++++++++++++-------------------------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index 5db7061bf9..a63ba4c37e 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1401,8 +1401,13 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts. /* Try to balance different loadable cargoes between parts of the consist, so that * all of them can be loaded. Avoid a situation where all vehicles suddenly switch - * to the first loadable cargo for which there is only one packet. */ - if (_returned_refit_capacity > 0 && consist_capleft[cid] < consist_capleft[new_cid]) { + * to the first loadable cargo for which there is only one packet. If the capacities + * are equal refit to the cargo of which most is available. This is important for + * consists of only a single vehicle as those will generally have a consist_capleft + * of 0 for all cargoes. */ + if (_returned_refit_capacity > 0 && (consist_capleft[cid] < consist_capleft[new_cid] || + (consist_capleft[cid] == consist_capleft[new_cid] && + st->goods[cid].cargo.AvailableCount() > st->goods[new_cid].cargo.AvailableCount()))) { new_cid = cid; } } diff --git a/src/linkgraph/demands.cpp b/src/linkgraph/demands.cpp index 80a0f56772..029d762344 100644 --- a/src/linkgraph/demands.cpp +++ b/src/linkgraph/demands.cpp @@ -11,15 +11,7 @@ typedef std::list NodeList; */ class Scaler { public: - /** - * Constructor. - */ - Scaler() : demand_per_node(0) {} - void SetDemands(LinkGraphJob &job, NodeID from, NodeID to, uint demand_forw); - -protected: - uint demand_per_node; ///< Mean demand associated with each node. }; /** @@ -32,7 +24,8 @@ public: * @param mod_size Size modifier to be used. Determines how much demands * increase with the supply of the remote station. */ - inline SymmetricScaler(uint mod_size) : mod_size(mod_size), supply_sum(0) + inline SymmetricScaler(uint mod_size) : mod_size(mod_size), supply_sum(0), + demand_per_node(0) {} /** @@ -80,8 +73,9 @@ public: void SetDemands(LinkGraphJob &job, NodeID from, NodeID to, uint demand_forw); private: - uint mod_size; ///< Size modifier. Determines how much demands increase with the supply of the remote station. - uint supply_sum; ///< Sum of all supplies in the component. + uint mod_size; ///< Size modifier. Determines how much demands increase with the supply of the remote station. + uint supply_sum; ///< Sum of all supplies in the component. + uint demand_per_node; ///< Mean demand associated with each node. }; /** @@ -90,37 +84,29 @@ private: class AsymmetricScaler : public Scaler { public: /** - * Constructor. + * Nothing to do here. + * @param unused. */ - inline AsymmetricScaler() : demand_sum(0) {} - - /** - * Count a node's demand into the sum of demands. - * @param node The node to be counted. - */ - inline void AddNode(const Node &node) + inline void AddNode(const Node &) { - this->demand_sum += node.Demand(); } /** - * Calculate the mean demand per node using the sum of demands. - * @param num_demands Number of accepting nodes. + * Nothing to do here. + * @param unused. */ - inline void SetDemandPerNode(uint num_demands) + inline void SetDemandPerNode(uint) { - this->demand_per_node = max(this->demand_sum / num_demands, (uint)1); } /** - * Get the effective supply of one node towards another one. In asymmetric - * distribution the demand of the other node is weighed in. + * Get the effective supply of one node towards another one. * @param from The supplying node. - * @param to The receiving node. + * @param unused. */ - inline uint EffectiveSupply(const Node &from, const Node &to) + inline uint EffectiveSupply(const Node &from, const Node &) { - return max(from.Supply() * to.Demand() / this->demand_per_node, (uint)1); + return from.Supply(); } /** @@ -130,9 +116,6 @@ public: * @param to_anno Unused. */ inline bool HasDemandLeft(const Node &to) { return to.Demand() > 0; } - -private: - uint demand_sum; ///< Sum of all demands in the component. }; /**