Skip to content

Commit

Permalink
很小概率发生逻辑错误版本,所有的机器人都可以投入工作
Browse files Browse the repository at this point in the history
  • Loading branch information
flybrotherhoi committed Mar 14, 2024
1 parent 58371df commit 1deb21e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
63 changes: 42 additions & 21 deletions Plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,38 +327,59 @@ class Plan
for(int i=0;i<10;i++){
robot[i].start_delay=0;
int conflict_flag=0;
if(MY_DEBUG)cerr<<"conflict flag: "<<conflict_flag<<endl;
vector<int> conflict_id;
for(int j=0;j<i;j++){
int t=0;
while(t+robot[j].start_delay<vec_robot_path[i].size()&&t<vec_robot_path[j].size()&&vec_robot_path[i][t+robot[j].start_delay]!=vec_robot_path[j][t]){
while(t+robot[j].start_delay+1<vec_robot_path[i].size()&&t<vec_robot_path[j].size()&&
diff_pair(vec_robot_path[i][t+robot[j].start_delay],vec_robot_path[j][t]) &&
diff_pair(vec_robot_path[i][t+robot[j].start_delay+1],vec_robot_path[j][t]) ){
t++;
}
if(t+robot[j].start_delay<vec_robot_path[i].size()&&t<vec_robot_path[j].size()){
if(t+robot[j].start_delay<vec_robot_path[i].size()-1&&t<vec_robot_path[j].size()){
conflict_flag=1;
conflict_id.push_back(j);
}
}
if(MY_DEBUG)cerr<<"conflict flag: "<<conflict_flag<<endl;
if(conflict_flag==1){
int start_delay = 1;
while(1){
int conflict_flag=0;
for(int j=0;j<i;j++){
int jsd = robot[j].start_delay;
int t=0;
while(t+jsd<vec_robot_path[i].size() && t<vec_robot_path[j].size() - start_delay&& vec_robot_path[i][t]!=vec_robot_path[j][t+start_delay]){
t++;
}
if(t<vec_robot_path[i].size()&&t<vec_robot_path[j].size()){
conflict_flag=1;
}
// int start_delay = 1;
// while(1){
// int conflict_flag=0;
// for(int j=0;j<i;j++){
// int jsd = robot[j].start_delay;
// int t=0;
// while(t+jsd-start_delay+1<vec_robot_path[i].size()-start_delay && t<vec_robot_path[j].size()
// && diff_pair(vec_robot_path[i][t+jsd-start_delay], vec_robot_path[j][t])
// && diff_pair(vec_robot_path[i][t+jsd-start_delay+1], vec_robot_path[j][t])){
// t++;
// }
// if(t+jsd-start_delay+1<vec_robot_path[i].size()-start_delay&&t<vec_robot_path[j].size()){
// conflict_flag=1;
// }
// // if(t<vec_robot_path[i].size()&&t<vec_robot_path[j].size()){
// // conflict_flag=1;
// // }
// }
// if(conflict_flag==0){
// robot[i].start_delay=start_delay;
// break;
// }
// start_delay++;
// if(MY_DEBUG)cerr<<"start delay: "<<start_delay<<endl;

//}
int start_delay=MAX_DIST;
for(int k=0;k<conflict_id.size();k++){
if(start_delay>(robot[conflict_id[k]].start_delay+vec_robot_path[conflict_id[k]].size())){
start_delay=robot[conflict_id[k]].start_delay+vec_robot_path[conflict_id[k]].size();
}
if(conflict_flag==0){
robot[i].start_delay=start_delay;
break;
}
start_delay++;
if(MY_DEBUG)cerr<<"start delay: "<<start_delay<<endl;
}
robot[i].start_delay=start_delay;
}
}
if(MY_DEBUG){
for(int i=0;i<10;i++){
cerr<<"robot "<<i<<" start delay: "<<robot[i].start_delay<<endl;
}
}

Expand Down
4 changes: 4 additions & 0 deletions RBB.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ RobotMove ReverseRobotMove(const RobotMove &move) {
return STAND;
};

bool diff_pair(const pair<int, int> &a, const pair<int, int> &b) {
return a.first != b.first || a.second != b.second;
}

class Robot
{
public:
Expand Down

0 comments on commit 1deb21e

Please sign in to comment.