LEMON Graph C++中的Map

vulvrdjw  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(142)

我需要一个非常简单的东西在柠檬,但我不能解决它。
我有一个加权图。弧上的权重。我需要将图作为类对象的一部分使用。因此,我将图形和ArcMap(权重所需)作为对象属性。现在,我有一个函数可以计算图形和Map,稍后我将需要在其他函数中使用图形和Map。
但是我不能在第一个函数中创建Map,然后将其分配给类的属性。我得到以下结果:

  1. 'operator=' is a private member of 'lemon::DigraphExtender<lemon::ListDigraphBase>::ArcMap<int>'

在文档中我没有发现任何东西,但它确实看起来是一个正常的东西,在一个函数上计算一些东西,然后将其用于另一个函数。
我的声明如下:

  1. ListDigraph::ArcMap<int>& length;

我在计算后要做的赋值是:

  1. ListDigraph::ArcMap<double> ll(g);
  2. this->length = ll;

其中g是:

  1. ListDigraph g;

声明为类的公共属性。
编辑:

  1. #include <algorithm>
  2. #include <random>
  3. #include <thread>
  4. #include <lemon/list_graph.h>
  5. #include <lemon/maps.h>
  6. #include "VLR_Config.h"
  7. #include "VLR_Feed.h"
  8. #include "VLR_Tools.h"
  9. using namespace lemon;
  10. class GraphSolver {
  11. public:
  12. void compute_graph() {
  13. for (auto const &t: seq_trips) {
  14. auto tid = t[0].trip_id;
  15. for (int i = 0; i < t.size() - 1; ++i) {
  16. auto from_sid = t[i].stop_id;
  17. auto to_sid = t[i + 1].stop_id;
  18. auto from_time = t[i].arrival_time;
  19. auto to_time = t[i + 1].arrival_time;
  20. auto delta = to_time - from_time;
  21. ListDigraph::NodeMap<int> node2stop(g);
  22. ListDigraph::Node from_node;
  23. ListDigraph::Node to_node;
  24. if (stop2node.find(from_sid) != stop2node.end())
  25. from_node = stop2node.at(from_sid);
  26. else {
  27. from_node = g.addNode();
  28. stop2node[from_sid] = from_node;
  29. node2stop[from_node] = from_sid;
  30. }
  31. if (stop2node.find(to_sid) != stop2node.end())
  32. to_node = stop2node.at(to_sid);
  33. else {
  34. to_node = g.addNode();
  35. stop2node[to_sid] = to_node;
  36. node2stop[to_node] = to_sid;
  37. }
  38. ListDigraph::Arc old_arc = findArc(g, from_node, to_node);
  39. if(old_arc == INVALID) {
  40. ListDigraph::Arc new_arc = g.addArc(from_node, to_node);
  41. length[new_arc] = delta;
  42. }
  43. else
  44. if(length[old_arc] < delta)
  45. length[old_arc] = delta;
  46. }
  47. }
  48. }
  49. // Collect StopTimes by trips
  50. SeqTrips seq_trips;
  51. MapStop2Idx stop2idx;
  52. VecStops stops;
  53. VecTrips trips;
  54. VecRoutes routes;
  55. ListDigraph g;
  56. unordered_map<size_t, ListDigraph::Node> stop2node;
  57. ListDigraph::ArcMap<int> length(g);
  58. };

最后一行有一个错误,因为我不能在那个上下文中传递g。但是,如果我没有传递g,那么在声明类GraphSolver的对象时,我会得到一个错误:

  1. 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

91zkwejq

91zkwejq1#

GraphSolver类需要一个构造函数。
两种可能性:
1.构造函数有一个参数,它指定了图形的大小-特别是弧的数量,以便GraphSolver构造函数可以构造图形并设置ArcMap的大小。
1.图形在其他地方构建,弧的数量传递给GraphSolver构造函数,以便它可以设置ArcMap的大小。

相关问题