A simple students project implementing Dinic's Algorithm to compute the max flow/min cut of a network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
1.9 KiB

#pragma once
#include <chrono>
#include <vector>
#include <set>
#include <string>
#include <fstream>
#include <iostream>
#include "util/GraphParser.h"
#include "util/Arc.h"
#define NO_AUGMENTING_PATH_FOUND -1
typedef std::vector<std::vector<Capacity>> CapacityMatrix;
namespace data {
class Graph {
public:
Graph(bool stdout_output, bool file_output, std::string output_filename, bool verbose_max_flow, bool min_cut, int verbosity);
void parseFromString(const std::string &graph_string);
void parseFromFile(const std::string &graph_file);
void maxFlowDinic();
private:
void initMatrices();
void setSourceAndSinkIterator();
void initOstream();
void constructLevelGraph();
int findAugmentingPaths();
void buildPath(std::vector<Vertex> &current_path);
void computeFlowForPath(const std::vector<Vertex> &current_path);
void printInformation() const;
void printMaxFlowInformation() const;
void printMinCut() const;
void printComputationStatistics(const std::chrono::steady_clock::time_point &start, const std::chrono::steady_clock::time_point &end) const;
std::vector<Vertex> m_vertices;
std::vector<Arc> m_arc_list;
VertexID m_source_id;
VertexID m_sink_id;
std::vector<Vertex>::iterator m_source;
std::vector<Vertex>::iterator m_sink;
CapacityMatrix m_flow;
CapacityMatrix m_capapcities;
int m_num_vertices;
int m_num_arcs;
int m_max_flow = 0;
bool m_stdout_output = true;
bool m_file_output = false;
std::string m_output_file_name;
std::ostream *m_ofstream;
bool m_verbose_max_flow = false;
bool m_min_cut = false;
int m_verbosity = 0;
uint m_num_paths = 0;
uint m_num_build_path_calls = 0;
uint m_num_level_graphs_built = 0;
std::vector<std::string> m_augmenting_paths;
};
}