Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Algorithm Analysis.pdf in Docs and simple notes in costflow.cpp

  • Loading branch information...
commit 57f9c24f950c5c6e0f9d1409e20610da95891df3 1 parent fad6e9b
Kaikai Zhu authored
Showing with 8 additions and 12 deletions.
  1. +8 −12 Sources/costflow.cpp
View
20 Sources/costflow.cpp
@@ -23,22 +23,20 @@ int inq[MAXN], Q[MAXN], dist[MAXN];
* 构图做最小费用最大流,以保证在当前情况下满足最多数量的order并且总代价最小
*/
-void addEdge(int a, int b, int f, int c) //加边函数,构图时用。a到b添加流量为f的,费用是c的边。
+void addEdge(int a, int b, int f, int c) /* 向图里面加边 */
{
flow[a][b] = f, flow[b][a] = 0;
cost[a][b] = c, cost[b][a] = -c;
}
-int BytheWay(Elevator *ele) // 判断电梯是不是空闲。
+int BytheWay(Elevator *ele, Order *order) /* 判断电梯是否空闲 */
{
- if (ele->Get_nPassenger() == Elevator::Get_capacity())
- return 0;
if (ele->Dir() == '-' && ele->Get_nPassenger() == 0 && ele->Get_inst()->size() == 0)
return 1;
else return 0;
}
-int spfa() // 费用流中求最小费用权路径。用spfa实现以加速。
+int spfa() /* 用SPFA实现最小费用流里面的寻找最小费用路径 */
{
memset(dist, -1, sizeof(dist));
memset(inq, 0, sizeof(inq));
@@ -70,7 +68,7 @@ void Controller::CostFLow()
int idx_order, idx_ele;
idx_order = 0;
for (OrderIter iter = order_s; iter != order_e; ++ iter)
- addEdge(S, ++ idx_order, 1, 0); // 每个order和S连边
+ addEdge(S, ++ idx_order, 1, 0); /* 每个order和S连边 */
idx_order = 0;
for (OrderIter iter = order_s; iter != order_e; ++ iter)
{
@@ -80,15 +78,13 @@ void Controller::CostFLow()
{
++ idx_ele;
- if (BytheWay(*jter))
- addEdge(idx_order, idx_ele, 1, abs((*jter)->Get_pos() - (*iter)->from)); // 对空闲的电梯和order连边
-
- //addEdge(idx_order, idx_ele, 1, estimate(*jter, *iter));
+ if (BytheWay(*jter, *iter))
+ addEdge(idx_order, idx_ele, 1, abs((*jter)->Get_pos() - (*iter)->from));
}
}
idx_ele = Emulator::orders.size();
for (EleIter iter = ele_s; iter != ele_e; ++ iter)
- addEdge(++ idx_ele, T, 1, 0); // 每个电梯和T连边
+ addEdge(++ idx_ele, T, 1, 0); /* 每个电梯和T连边 */
while (spfa())
{
@@ -107,7 +103,7 @@ void Controller::CostFLow()
for (EleIter jter = ele_s; jter != ele_e; ++ jter)
{
++ idx_ele;
- if (flow[idx_ele][idx_order] == 1) // 判断这个order是不是被接了,如果被接了,那么有一个电梯的流会被堵住。
+ if (flow[idx_ele][idx_order] == 1) /* 如果该电梯的流被堵塞,说明接了这个order */
{
(*jter)->PushInst(new Instruction((*iter)->from, 1));
flag = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.