我需要一个非常简单的东西在柠檬,但我不能解决它。
我有一个加权图。弧上的权重。我需要将图作为类对象的一部分使用。因此,我将图形和ArcMap(权重所需)作为对象属性。现在,我有一个函数可以计算图形和Map,稍后我将需要在其他函数中使用图形和Map。
但是我不能在第一个函数中创建Map,然后将其分配给类的属性。我得到以下结果:
'operator=' is a private member of 'lemon::DigraphExtender<lemon::ListDigraphBase>::ArcMap<int>'
在文档中我没有发现任何东西,但它确实看起来是一个正常的东西,在一个函数上计算一些东西,然后将其用于另一个函数。
我的声明如下:
ListDigraph::ArcMap<int>& length;
我在计算后要做的赋值是:
ListDigraph::ArcMap<double> ll(g);
this->length = ll;
其中g是:
ListDigraph g;
声明为类的公共属性。
编辑:
#include <algorithm>
#include <random>
#include <thread>
#include <lemon/list_graph.h>
#include <lemon/maps.h>
#include "VLR_Config.h"
#include "VLR_Feed.h"
#include "VLR_Tools.h"
using namespace lemon;
class GraphSolver {
public:
void compute_graph() {
for (auto const &t: seq_trips) {
auto tid = t[0].trip_id;
for (int i = 0; i < t.size() - 1; ++i) {
auto from_sid = t[i].stop_id;
auto to_sid = t[i + 1].stop_id;
auto from_time = t[i].arrival_time;
auto to_time = t[i + 1].arrival_time;
auto delta = to_time - from_time;
ListDigraph::NodeMap<int> node2stop(g);
ListDigraph::Node from_node;
ListDigraph::Node to_node;
if (stop2node.find(from_sid) != stop2node.end())
from_node = stop2node.at(from_sid);
else {
from_node = g.addNode();
stop2node[from_sid] = from_node;
node2stop[from_node] = from_sid;
}
if (stop2node.find(to_sid) != stop2node.end())
to_node = stop2node.at(to_sid);
else {
to_node = g.addNode();
stop2node[to_sid] = to_node;
node2stop[to_node] = to_sid;
}
ListDigraph::Arc old_arc = findArc(g, from_node, to_node);
if(old_arc == INVALID) {
ListDigraph::Arc new_arc = g.addArc(from_node, to_node);
length[new_arc] = delta;
}
else
if(length[old_arc] < delta)
length[old_arc] = delta;
}
}
}
// Collect StopTimes by trips
SeqTrips seq_trips;
MapStop2Idx stop2idx;
VecStops stops;
VecTrips trips;
VecRoutes routes;
ListDigraph g;
unordered_map<size_t, ListDigraph::Node> stop2node;
ListDigraph::ArcMap<int> length(g);
};
最后一行有一个错误,因为我不能在那个上下文中传递g
。但是,如果我没有传递g
,那么在声明类GraphSolver的对象时,我会得到一个错误:
GraphSolver graph_solver;
给出错误Call to implicitly-deleted default constructor of 'VLR::GraphSolver' default constructor of 'GraphSolver' is implicitly deleted because field 'length' has no default constructor
1条答案
按热度按时间91zkwejq1#
GraphSolver类需要一个构造函数。
两种可能性:
1.构造函数有一个参数,它指定了图形的大小-特别是弧的数量,以便GraphSolver构造函数可以构造图形并设置ArcMap的大小。
1.图形在其他地方构建,弧的数量传递给GraphSolver构造函数,以便它可以设置ArcMap的大小。