저는 오랫동안 Cpp에서 프로그래밍 중이며 한 곳에서 머물러 있습니다. 코드는 아래와 같습니다 (그 때문에 인내심을 오래) :요소를 대기열에 푸시하는 동안 세그먼트 오류가 발생했습니다.
bool mazerouter(int xs, int ys, int ps, int xt, int yt, int pt)
{
int n = gn; int w = gw;
// The expansion list as maintained by the maze router. Could be declared as a class variable
// but then, we need to find a way to empty the queue every time mazerouter is exited.
queue <Wire_seg> explist;
// Step 1: mark all the track segments that are available and adjacent to target as "t".
// this depends on pin number.
vector < vector<int> > target = getWireSegments(xt, yt, pt);
//int skip = 1/fc_in;
int i,j;
std::vector < std::vector <Wire_seg> > HorzWire = fpga.getHorzWire();
std::vector < std::vector <Wire_seg> > VertWire = fpga.getVertWire();
for (i = 0; i < target.size(); i = i+2)
{
if (pt == 1 || pt == 3)
{
if (VertWire[ target[i][0]][ target[i][1] ].getTag() == "a")
VertWire[ target[i][0] ][ target[i][1] ].setTag("t");
}
else if (pt == 2)
{
if (HorzWire[ target[i][0]][ target[i][1] ].getTag() == "a")
HorzWire[ target[i][0] ][ target[i][1] ].setTag("t");
}
} cout<<"Completed routing step 1\n";
// Step 2: mark all the track segments that are available and adjacent to source as "o".
// Push all the wire_segs in expansion list.
vector < vector<int> > source = getWireSegments(xs, ys, ps);
//skip = 1/fc_out;
len = 0; // for initialization of the source wire segments
for (i = 0; i < source.size(); i = i+1)
{
if (HorzWire[ source[i][0] ][ source[i][1] ].getTag() == "a")
{
HorzWire[ source[i][0] ][ source[i][1] ].setNtag(0);
HorzWire[ source[i][0] ][ source[i][1] ].setTag("u");
explist.push(HorzWire[ source[i][0] ][ source[i][1] ]);
}
} cout<<"Completed routing step 2 and expansion list size: "<<explist.size()<<"\n";
// The while loop
bool pathfound = false;
vector < vector <int> > h;
vector < vector <int> > v;
while (!explist.empty())
{
Wire_seg ws = explist.front();
cout<<"Completed routing step 3 substep 1 with front's tag:"<<explist.front().getTag()<<"\n";
explist.pop();
h = ws.getHorzCon();
v = ws.getVertCon();
len = ws.getNtag() + 1;
int a;
for (a = 0; a < h.size(); a++)
{
if (HorzWire[ h[a][0] ][ h[a][1] ].getTag() == "t")
{
cout<<"target hit in horzwire\n";
pathfound = true;
//path.push_back( vector <string>()); pl++;
//path.at(pl).push_back(fpga.getHorzWire(h[a][0], h[a][1]).getUid());
break;
}
else if (HorzWire[ h[a][0] ][ h[a][1] ].getTag() == "a")
{
HorzWire[ h[a][0] ][ h[a][1] ].setTag("u");HorzWire[ h[a][0] ][ h[a][1] ].setNtag(len);
cout<<"target not found, pushing horzwire("<<h[a][0]<<","<<h[a][1]<<") in explist with new tag:"<<HorzWire[ h[a][0] ][ h[a][1] ].getTag()<<"\n";
explist.push(HorzWire[ h[a][0] ][ h[a][1] ]);
}
}
cout<<"Completed routing step 3 substep 2\n";
for (a = 0; a < v.size(); a++)
{
if (VertWire[ v[a][0] ][ v[a][1] ].getTag() == "t")
{
pathfound = true;
//path.push_back( vector <string>()); pl++;
//path.at(pl).push_back(fpga.getVertWire(v[a][0], v[a][1]).getUid());
break;
}
else if (VertWire[ v[a][0] ][ v[a][1] ].getTag() == "a")
{
VertWire[ v[a][0] ][ v[a][1] ].setTag("u"); VertWire[ v[a][0] ][ v[a][1] ].setNtag(len);
// the following is the line causing trouble
explist.push(VertWire[ v[a][0] ][ v[a][1] ]); <=================================================================
cout<<"target not found, pushing vertwire("<<v[a][0]<<","<<v[a][1]<<") in explist with new tag:"<<VertWire[ v[a][0] ][ v[a][1] ].getTag()<<"\n";
}
}
h.clear();
v.clear();
cout<<"Completed routing step 3 substep 3 and expansion list size: "<<explist.size()<<"\n";
}// end while
cout<<"Completed routing step 3\n";
return pathfound;
}// end mazerouter
내가 라인 세그먼트 오류를 얻고있다 'explist.push (VertWire [V [A] [0] [V [A] [ 1]]); "코드로"< == "으로 표시되었습니다. 일단 내가 주석을 달고 코드를 실행하면 오류가 발생하지 않지만 물론, 내 문제에 대한 해결책은 없습니다. 내가 뭘 잘못하고있어? 큰 도움이 될거야. 사전에 감사합니다
이 기능은 무엇입니까 : 주어진 소스 블록 (xs, ys) 및 들어오는 방향 (ps, east, west, north, 남쪽) 및 대상 블록 (xs, ys)과 나가는 방향 (pt, ps와 동일)을 연결하려면 경로를 찾아야합니다. 실제로, Wire_seg Logic_Block 클래스로 구현 된 논리 블록 사이의 와이어 세그먼트에 대한 클래스 및 논리 블록 사이의 경로를합니다.
VertWire [v [a] [0]] [v [a] [1]]의 인쇄 값에 관해서는 클래스이며 따라서 멤버 변수 태그에 액세스하고 있습니다. 그것은 존재한다.
@ 대니얼 : 저는 이미 g ++ 컴파일러를 사용하고 있습니다.
"Wire_seg.h"에 대한 코드는 다음과 같습니다
class Wire_seg
{
// the track number for each wire segment, varies from 0 to w-1.
int tno;
// the orientation of the wire segment.
char ornt;
// vector to store the indices of all possible connections that can be made from
// this wire segment.
std::vector < std::vector<int> > horz_con;
std::vector < std::vector<int> > vert_con;
//an unique id given to each wire of the following format "ornt:row:col"
std::string uid;
// The tag that helps determine whether this wire is availabel for a path or not.
// initially all wires are available.
std::string tag;
int ntag;
public:
Wire_seg()
{
tag = "a";
}
void setHorzCon(std::vector < std::vector<int> > h)
{
horz_con = h;
}
void setVertCon(std::vector < std::vector<int> > v)
{
vert_con = v;
}
void setTno(int t)
{
tno = t;
}
void setOrnt(char orientation)
{
ornt = orientation;
}
void setUid(std::string id)
{
uid = id;
}
void setTag(std::string t)
{
tag.assign(t);
}
void setNtag(int t)
{
ntag = t;
}
int getTno()
{
return tno;
}
char getOrnt()
{
return ornt;
}
std::vector < std::vector<int> > getHorzCon()
{
return horz_con;
}
std::vector < std::vector<int> > getVertCon()
{
return vert_con;
}
std::string getUid()
{
return uid;
}
std::string getTag()
{
return tag;
}
int getNtag()
{
return ntag;
}
};
나는이 문제가 더 명확하게 바랍니다.
이 기능의 기능에 대해 설명해 주시겠습니까? 폭경 우선 검색을 사용하여 미로를 해결하려는 것 같습니다. 맞습니까? 와이어 변수는 무엇입니까? – Pubby
VertWire [v [a] [0]] [v [a] [1]]의 값을 인쇄 해 보았습니까? 충돌 할 경우 UB를 일으키는 범위를 벗어나는 어레이에 액세스하고 있음을 알 수 있습니다. –
'Wire_seg', esp에 대한 코드를 게시하십시오. 생성자/소멸자. – NPE