从C+中的拓扑生成邻接列表图+; 作为C++初学者,我需要做一个邻接表图。我想生成一个加权图,显示平面之间的拓扑关系及其角度作为权重。因此在图中,平面表示图的顶点(例如v),交线表示图的边(例如v1v2)。每条相交线也有一个属性。我的程序生成这样一个txt文件: for (planes.begin, numberOFplanes, planei++){ for(planes.begin+1, numberOFplanes, planej++){ if (planei intersect planej){ cout << ViVj << attribute << angle << nedl; } } }
边缘、属性、权重从C+中的拓扑生成邻接列表图+; 作为C++初学者,我需要做一个邻接表图。我想生成一个加权图,显示平面之间的拓扑关系及其角度作为权重。因此在图中,平面表示图的顶点(例如v),交线表示图的边(例如v1v2)。每条相交线也有一个属性。我的程序生成这样一个txt文件: for (planes.begin, numberOFplanes, planei++){ for(planes.begin+1, numberOFplanes, planej++){ if (planei intersect planej){ cout << ViVj << attribute << angle << nedl; } } },c++,graph,adjacency-list,topology,C++,Graph,Adjacency List,Topology,边缘、属性、权重 v1v2,1,90 v1v3,2,45 v1v3,2,30 v2v3,3,90 下面是生成txt文件的伪代码: for (planes.begin, numberOFplanes, planei++){ for(planes.begin+1, numberOFplanes, planej++){ if (planei intersect planej){ cout << ViVj << attribute <<
v1v2,1,90
v1v3,2,45
v1v3,2,30
v2v3,3,90
下面是生成txt文件的伪代码:
for (planes.begin, numberOFplanes, planei++){
for(planes.begin+1, numberOFplanes, planej++){
if (planei intersect planej){
cout << ViVj << attribute << angle << nedl;
}
}
}
for(planes.begin、numberOFplanes、planei++){
对于(planes.begin+1,numberOFplanes,planej++){
如果(平面i与平面j相交){
如果我不明白这一点或那一点,请不要犹豫纠正我
让我们从我们需要的基本几何对象开始:
//I considere here the one point + one orthogonal
//representation of a plan
class Plan{
public:
//Constructor
Node(const Point*& iPoint, const Vector*& iVector) {
_point = iPoint;
_vector = iVector;
}
float getAngleDifferencial(const Plan*& iPlan) {
//well my math are a bit old too do the math
//but you should be fine here... I hope :)
}
//you may wanna add getter or stuff like that
private:
Point* _point;
Vector* _vector;
}
接下来是图表项:
class Node {
public:
Node(int iNumber,const Plan*& iPlan):
_Id(iNumber) {
_Plan = iPlan;
}
private:
int _Id;
Plan* _Plan;
}
class Edge {
public:
Edge(const Node*& iNode1,const Node*&iNode2) {
if (iNode1->getId()==iNode2->getId()) {
//throw Exception
}
_Node1 = iNode1;
_Node2 = iNode2;
_Weight = iNode1->getPlan()->getAngleDifferencial(iNode2->getPlan())
}
private:
Node* _Node1;
Node* _Node2;
float _Weight;
}
最后,您需要获得一些数组来放置节点和边,并开始使用它
玩得开心:)@88877我的输入是平面列表。无向加权图的一个实现示例: