private void MoveNextEdge(Edge edge, float deltaGoodFromStart) { var nextNodePassedCount = CountPassed(edge.To); var progressScale = (float)_uniqPassedNodesCount / _totalNodesCount; //weight 200 :Total path search progress (how much it is completed/finished) var nextNodeScoreScale = 1f / (nextNodePassedCount * nextNodePassedCount + 1); //weight 200 :Lower value if next node was visited more times var pc = _uniqPassedNodesCount; if (nextNodePassedCount == 0) { pc++; } var pathNoRepeatedNodesScoreScale = (float)pc / (_totalPassedNodesCount + 1); //weight 400 :Higher value if all nodes was visited less times var progressScaleValue = progressScale * 1; var nextNodeScoreValue = nextNodeScoreScale * 300; var deltaGoodFromStartValue = deltaGoodFromStart * 500 * nextNodeScoreScale; var pathNoRepeatedNodesScoreValue = pathNoRepeatedNodesScoreScale * 800; //iterations with bigger score will be processed earlier var totalScore = progressScaleValue + nextNodeScoreValue + deltaGoodFromStartValue + pathNoRepeatedNodesScoreValue; var dbg = $"Progress: {progressScaleValue} NextNode({edge.To.Id}): {nextNodeScoreValue} GoodStart: {deltaGoodFromStartValue} NoRepeat: {pathNoRepeatedNodesScoreValue}"; var newStep = new BbIterationStep(this, edge, dbg, totalScore); BranchNBound.Instance.AddStep(newStep, totalScore); }
public void AddStep(BbIterationStep step, float cost) { step.VariantId = IdCounter++; if (!_iterations.TryGetValue(cost, out var list)) { list = new List <BbIterationStep>(); _iterations.Add(cost, list); } list.Add(step); }
public BbIterationStep(BbIterationStep from, Edge currentEdge, string debug, float score) { Parent = from; Score = score; _currentEdge = currentEdge; Debug = debug; Node = _currentEdge.From; _uniqPassedNodesCount = from._uniqPassedNodesCount; _totalPassedNodesCount = from._totalPassedNodesCount; _totalNodesCount = from._totalNodesCount; }
public void RegisterGoodPath(BbIterationStep step) { if (step._uniqPassedNodesCount < MaxNodesVisited) { return; } if (step._uniqPassedNodesCount > MaxNodesVisited) { BestPath.Clear(); MaxNodesVisited = step._uniqPassedNodesCount; } BestPath.Add(step); }