Files
openttd/src/linkgraph/mcf.h
Jonathan G Rennison d09b504bc5 Merge branch 'master' into jgrpp
# Conflicts:
#	.github/workflows/ci-build.yml
#	.github/workflows/release-linux.yml
#	.github/workflows/release-macos.yml
#	.github/workflows/release-source.yml
#	.github/workflows/release.yml
#	CMakeLists.txt
#	COMPILING.md
#	src/ai/ai_core.cpp
#	src/ai/ai_gui.cpp
#	src/bridge_gui.cpp
#	src/company_gui.cpp
#	src/console_cmds.cpp
#	src/core/CMakeLists.txt
#	src/core/smallmap_type.hpp
#	src/disaster_vehicle.h
#	src/effectvehicle_base.h
#	src/fontcache.cpp
#	src/game/game_core.cpp
#	src/game/game_gui.cpp
#	src/gamelog.cpp
#	src/gamelog_internal.h
#	src/group_gui.cpp
#	src/linkgraph/linkgraph.h
#	src/misc.cpp
#	src/network/core/config.h
#	src/network/core/udp.cpp
#	src/network/network_chat_gui.cpp
#	src/network/network_content_gui.cpp
#	src/network/network_gui.cpp
#	src/newgrf.cpp
#	src/newgrf_gui.cpp
#	src/newgrf_profiling.cpp
#	src/newgrf_profiling.h
#	src/object_gui.cpp
#	src/openttd.cpp
#	src/openttd.h
#	src/order_gui.cpp
#	src/os/windows/font_win32.cpp
#	src/rail_gui.cpp
#	src/road.cpp
#	src/road_gui.cpp
#	src/saveload/afterload.cpp
#	src/saveload/saveload.h
#	src/script/api/script_controller.cpp
#	src/script/api/script_roadtypelist.cpp
#	src/script/script_config.cpp
#	src/script/script_config.hpp
#	src/script/script_instance.cpp
#	src/script/script_scanner.cpp
#	src/script/squirrel.cpp
#	src/script/squirrel_helper.hpp
#	src/settings_gui.cpp
#	src/settings_internal.h
#	src/settings_type.h
#	src/table/settings/network_private_settings.ini
#	src/timetable_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/window_gui.h
2023-07-01 02:42:51 +01:00

88 lines
2.8 KiB
C++

/** @file mcf.h Declaration of Multi-Commodity-Flow solver */
#ifndef MCF_H
#define MCF_H
#include "linkgraphjob_base.h"
#include <vector>
typedef std::vector<Path *> PathVector;
/**
* Multi-commodity flow calculating base class.
*/
class MultiCommodityFlow {
protected:
/**
* Constructor.
* @param job Link graph job being executed.
*/
MultiCommodityFlow(LinkGraphJob &job) : job(job),
max_saturation(job.Settings().short_path_saturation)
{}
template<class Tannotation, class Tedge_iterator>
void Dijkstra(NodeID from, PathVector &paths);
uint PushFlow(DemandAnnotation &anno, Path *path, uint min_step_size, uint accuracy, uint max_saturation);
void CleanupPaths(NodeID source, PathVector &paths);
LinkGraphJob &job; ///< Job we're working with.
uint max_saturation; ///< Maximum saturation for edges.
};
/**
* First pass of the MCF calculation. Saturates shortest paths first, creates
* new paths if needed, eliminates cycles. This calculation is of exponential
* complexity in the number of nodes but the constant factors are sufficiently
* small to make it usable for most real-life link graph components. You can
* deal with performance problems that might occur here in multiple ways:
* - The overall accuracy is used here to determine how much flow is assigned
* in each loop. The lower the accuracy, the more flow is assigned, the less
* loops it takes to assign all flow.
* - The short_path_saturation setting determines when this pass stops. The
* lower you set it, the less flow will be assigned in this pass, the less
* time it will take.
* - You can increase the recalculation interval to allow for longer running
* times without creating lags.
*/
class MCF1stPass : public MultiCommodityFlow {
private:
bool EliminateCycles();
bool EliminateCycles(PathVector &path, NodeID origin_id, NodeID next_id);
void EliminateCycle(PathVector &path, Path *cycle_begin, uint flow);
uint FindCycleFlow(const PathVector &path, const Path *cycle_begin);
public:
MCF1stPass(LinkGraphJob &job);
};
/**
* Second pass of the MCF calculation. Saturates paths with most capacity left
* first and doesn't create any paths along edges that haven't been visited in
* the first pass. This is why it doesn't have to do any cycle detection and
* elimination. As cycle detection is the most intense problem in the first
* pass this pass is cheaper. The accuracy is used here, too.
*/
class MCF2ndPass : public MultiCommodityFlow {
public:
MCF2ndPass(LinkGraphJob &job);
};
/**
* Link graph handler for MCF. Creates MultiCommodityFlow instance according to
* the template parameter.
*/
template<class Tpass>
class MCFHandler : public ComponentHandler {
public:
/**
* Run the calculation.
* @param graph Component to be calculated.
*/
virtual void Run(LinkGraphJob &job) const { Tpass pass(job); }
};
#endif /* MCF_H */