Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 增压最大流量不';使用模板directedgraph时是否编译?_C++_Boost_Graph_Max_Flow - Fatal编程技术网

C++ 增压最大流量不';使用模板directedgraph时是否编译?

C++ 增压最大流量不';使用模板directedgraph时是否编译?,c++,boost,graph,max,flow,C++,Boost,Graph,Max,Flow,我想用boost图库计算最大流。 根据请求更新以下是完整代码:+ CPP: 虽然我提供了所有必要的参数,但它没有编译。我收到了很长的无法读取的错误消息,但我认为问题与图形类型有关。错误如下所示: 错误:从“boost::detail::edge\u desc\u impl boost::directed\u标记,long-long unsigned int”转换为非标量类型 boost::detail::push\u relabel boost::labeled\u graph boost::d

我想用boost图库计算最大流。 根据请求更新以下是完整代码:+

CPP: 虽然我提供了所有必要的参数,但它没有编译。我收到了很长的无法读取的错误消息,但我认为问题与图形类型有关。错误如下所示:

错误:从“boost::detail::edge\u desc\u impl boost::directed\u标记,long-long unsigned int”转换为非标量类型 boost::detail::push\u relabel boost::labeled\u graph boost::directed\u graph VertexProperty


必须移除标志以使stackoverflows引用功能接受错误

请给我们看一下
new\u src
new\u sink
的声明好吗?为了能够提供帮助,我们错过了一点背景知识。天哪。您可以只显示未编译的代码。这肯定是v-v-FAQ中的一个,如果我们能给你看,那就太方便了。我添加了代码。我做了一些研究,发现有向图类模板似乎与最大流算法不兼容。有人能证实吗?如果我使用邻接列表模板编译没有失败,那么当我运行push_relabel_max_flow函数时,我会出现分段错误,我的代码有什么问题,我还需要提供什么才能使算法工作?
#include <iostream>
#include "PPINetwork.h"
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/read_dimacs.hpp>
#include <boost/graph/boykov_kolmogorov_max_flow.hpp>
#include <boost/graph/push_relabel_max_flow.hpp>

#include "interactions.h"


using namespace std;

void PPINetwork::addEdge(string &p1, string &p2, double w){
 Vertex s,e;
 if(g.vertex(p1)==g.null_vertex()){
   s = g.add_vertex(p1);
   g.graph()[s].name = p1;
 }
 else
   s = g.vertex(p1);
 if(g.vertex(p2)==g.null_vertex()){
   e = g.add_vertex(p2);
   g.graph()[e].name = p2;
 }
 else
   e = g.vertex(p2);

 g.graph().add_edge(s,e,{1-w,w});

}

void PPINetwork::readNetwork(ifstream &ppin_file) {

 // Create a graph object
 string line;
 std::getline(ppin_file, line); //skip header
 while (std::getline(ppin_file, line)) {
 std::istringstream iss(line);
 string p1, p2;
 float w;
 if (!(iss >> p1 >> p2 >> w)) {
  throw invalid_argument("line has wrong formaat\n" + line);
 } // error
 addEdge(p1,p2,w);
}
cout << "read " << boost::num_edges(g) << " Edges" << std::endl;
}

PPINetwork::PPINetwork(ifstream &file) {
 readNetwork(file);
}

double PPINetwork::maxflow(vector<string> srcs,vector<string> sinks) {
//add common src and sink
 vector<string> src_verticies;
 vector<string> sink_verticies;
 //filter out non existing verticies
 for (string s: srcs) {
   Vertex src_v = g.vertex(s);
   if (src_v != g.null_vertex())
    src_verticies.push_back(s);
   }
  for (string s: sinks) {
   Vertex sink_v = g.vertex(s);
  if (sink_v != g.null_vertex())
   sink_verticies.push_back(s);
 }
 double max_double = std::numeric_limits<double>::max();
 Vertex new_src = g.add_vertex("new_src");
 Vertex new_sink = g.add_vertex("new_sink");
 string ssrc = "new_src";
 string ssink = "new_sink";
 // add common sink and src
 for (string &s : src_verticies) {
  addEdge(ssrc, s, max_double);
 }
 for (string &s : src_verticies) {
  addEdge(s, ssink, max_double);
 }
 auto capacity = boost::get(boost::edge_capacity, g);
 auto reverse  = boost::get(boost::edge_reverse, g);
 auto residcap = boost::get(boost::edge_residual_capacity, g);
 auto indexmap = boost::get(boost::vertex_index, g);

 double flow = boost::push_relabel_max_flow(g, new_src, new_sink,capacity,residcap, reverse, indexmap);
}

PPINetwork::PPINetwork() {

}
#ifndef UNTITLED_PPINETWORK_H
#define UNTITLED_PPINETWORK_H

#include <fstream>
#include <boost/graph/properties.hpp>
#include <boost/graph/undirected_graph.hpp>
#include <boost/graph/directed_graph.hpp>
#include <boost/graph/labeled_graph.hpp>
#include <vector>


using namespace std;
struct VertexProperty
{
 string name;
};
 typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::directedS> Traits;
 typedef boost::property<boost::edge_reverse_t, Traits::edge_descriptor> rev;
 typedef boost::property<boost::edge_weight_t, double,
  boost::property<boost::edge_capacity_t, double,
   boost::property<boost::edge_residual_capacity_t, long,
    rev > > > EdgeDesc;
 typedef boost::labeled_graph<boost::directed_graph<VertexProperty,EdgeDesc>,std::string> diGraph;
 typedef unordered_map<string,unordered_map<string,double>> ssf_map;
 typedef  boost::graph_traits<diGraph>::vertex_descriptor Vertex;
 typedef boost::graph_traits < diGraph >::edge_descriptor Edge;

class PPINetwork {
 public:
  PPINetwork();
  PPINetwork(ifstream &ppin_file);
  void addEdge(string &p1, string &p2, double w);
  double maxflow(vector<string> srcs,vector<string> sinks);


 private:
  void readNetwork(ifstream &ppin_file);
 diGraph g;
};

#endif //UNTITLED_PPINETWORK_H
double flow = boost::push_relabel_max_flow(g, new_src,new_sink,capacity,residcap, reverse, indexmap);}