重写的请求判断函数,重写了顺逆时针路程计数部分

This commit is contained in:
jackfiled 2022-05-29 21:21:49 +08:00
parent 2d9ca19cd5
commit a0ba048cbf
2 changed files with 34 additions and 23 deletions

View File

@ -40,10 +40,10 @@ bus_query_t *SSTFGetQuery();
/** /**
* *
* SSTF策略中使用 * SSTF策略中使用
* @param target_query * @param query
* @return * @return
*/ */
int SSTFDirection(bus_query_t* target_query); int SSTFDirection(bus_query_t* query);
/** /**
* 便 * 便
@ -60,10 +60,10 @@ bus_query_t *SCANGetQuery();
/** /**
* *
* SCAN策略中使用 * SCAN策略中使用
* @param target_query * @param query
* @return * @return
*/ */
int SCANDirection(bus_query_t *target_query); int SCANDirection(bus_query_t *query);
/** /**
* 便 * 便

View File

@ -19,17 +19,29 @@ int FCFSDirection()
{ {
int clockwise = 0; int clockwise = 0;
int counterclockwise = 0; //用于顺,逆时针方向所经站台计数 int counterclockwise = 0; //用于顺,逆时针方向所经站台计数
while(p->node != p->next_node->node) /**
*
*/
rail_node_t *now_position = the_bus->rail_node_pos;
/**
*
*/
rail_node_t *target_position = p->node;
rail_node_t *pos = now_position;
while (pos != target_position) //顺时针计数
{ {
p->node = p->node->next_node;
clockwise++; clockwise++;
}//顺时针方向计数 pos = pos->next_node;
while(p->node != p->next_node->node) }
pos = now_position;
while (pos != target_position) //逆时针计数
{ {
p->next_node->node = p->next_node->node->next_node;
counterclockwise++; counterclockwise++;
}//逆时针方向计数 pos = pos->last_node;
}
if(clockwise <= counterclockwise) if(clockwise <= counterclockwise)
{ {
@ -40,22 +52,21 @@ int FCFSDirection()
return BUS_COUNTER_CLOCK_WISE; return BUS_COUNTER_CLOCK_WISE;
}//若逆时针距离短,公交车逆时针运行 }//若逆时针距离短,公交车逆时针运行
} }
} }
bus_query_t *FCFSQuery() bus_query_t *FCFSQuery()
{ {
bus_query_t *p = queries; bus_query_t *result = NULL;
if (the_bus->rail_node_pos == p->node)
if(queries != NULL)
{ {
queries = queries->next_node; if(the_bus->rail_node_pos == queries->node)
return p; {
} result = queries;
else }
{
return NULL;
} }
return result;
} }
bus_query_t *SSTFGetQuery() bus_query_t *SSTFGetQuery()
@ -63,7 +74,7 @@ bus_query_t *SSTFGetQuery()
return NULL; return NULL;
} }
int SSTFDirection(bus_query_t* target_query) int SSTFDirection(bus_query_t* query)
{ {
return BUS_STOP; return BUS_STOP;
} }
@ -78,7 +89,7 @@ bus_query_t *SCANGetQuery()
return NULL; return NULL;
} }
int SCANDirection(bus_query_t *target_query) int SCANDirection(bus_query_t *query)
{ {
return BUS_STOP; return BUS_STOP;
} }