Commit 7bff1021 authored by 神楽坂玲奈's avatar 神楽坂玲奈

test

parent 85b84cbb
[ [
{ {
"id": 1800, "id": 3,
"routers": [ "routers": [
1, 1,
3 3
......
...@@ -38,7 +38,7 @@ export class Router { ...@@ -38,7 +38,7 @@ export class Router {
this.via.set(router, router); this.via.set(router, router);
} }
for (const plan of plans.filter(plan => !plan.routers.includes(this.id))) { for (const plan of plans.filter(plan => !plan.routers.includes(this.id))) {
this.plan[plan.id] = Router.all.find(r => r.id == plan.routers[0])!.id; this.plan[plan.id] = this.id;
} }
} }
...@@ -112,19 +112,22 @@ export class Router { ...@@ -112,19 +112,22 @@ export class Router {
} }
} }
const changedPlan: Record<number, number | null> = {};
// 计算 route plan
// 凡是自己可以作为那个 plan 出口的,是不会计算直接跳过的,所以这里有 plan 到自己的意思是,没有找到任何一个通的可以出的地方,所以只好从自己出了
const changedPlan: Record<number, number> = {};
for (const plan of plans.filter(plan => !plan.routers.includes(this.id))) { for (const plan of plans.filter(plan => !plan.routers.includes(this.id))) {
const currentPlan = this.plan[plan.id]; const currentPlan = this.plan[plan.id];
const currentMetric = const currentMetric = currentPlan === this.id ? Infinity : metric[currentPlan];
const items = plan.routers.map(to => [to, metric[to]]); const items = plan.routers.map(to => [to, metric[to]]);
const [bestPlan, bestMetric] = _.minBy(items, ([t, m]) => m)!; const [bestPlan, bestMetric] = _.minBy(items, ([t, m]) => m)!;
if (bestMetric === Infinity) { if (currentPlan !== this.id && bestMetric === Infinity) {
changedPlan[plan.id] = null; // 原来通的,现在不通了
} else { changedPlan[plan.id] = this.id;
} else if (currentPlan !== bestPlan && bestMetric + config.throttle < currentMetric) {
changedPlan[plan.id] = bestPlan; changedPlan[plan.id] = bestPlan;
} }
} }
if (!_.isEmpty(changedVia) || !_.isEmpty(changedPlan)) { if (!_.isEmpty(changedVia) || !_.isEmpty(changedPlan)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment