路径算法调整为动态规划方式,新增预任务申请功能
This commit is contained in:
69
WarehouseMgr/Tnb.WarehouseMgr/Dp.cs
Normal file
69
WarehouseMgr/Tnb.WarehouseMgr/Dp.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Templates;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Spire.Doc;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态规划类
|
||||
/// </summary>
|
||||
public class Dp
|
||||
{
|
||||
private const int Max = int.MaxValue;
|
||||
private int Min = int.MaxValue;
|
||||
private int Deep = 0;
|
||||
/// <summary>
|
||||
/// 动态规划函数
|
||||
/// </summary>
|
||||
/// <param name="roads"></param>
|
||||
/// <param name="sPointId"></param>
|
||||
/// <param name="ePointId"></param>
|
||||
/// <returns></returns>
|
||||
public void DpFunc(List<WmsRoad> roads, List<WmsRoad> subRoads, List<string> pointIds, Dictionary<string, bool> isVisited, string sPointId, string ePointId)
|
||||
{
|
||||
Deep++;
|
||||
|
||||
var sRoads = roads.FindAll(x => x.startpoint_id == sPointId).ToList();
|
||||
var sRoads_EPointIds = sRoads.Select(x => x.endpoint_id).ToList();
|
||||
|
||||
if (!isVisited[sPointId])
|
||||
{
|
||||
Console.WriteLine($"code={roads.Find(x => x.startpoint_id == sPointId).startpoint_code}");
|
||||
pointIds.Add(sPointId);
|
||||
}
|
||||
var eSubRoads = sRoads.FindAll(x => x.endpoint_id == ePointId);
|
||||
if (eSubRoads?.Count > 0)
|
||||
{
|
||||
pointIds.Add(ePointId);
|
||||
Console.WriteLine($"Deep={Deep}");
|
||||
foreach (var kvp in isVisited)
|
||||
{
|
||||
isVisited[kvp.Key] = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
subRoads = roads.FindAll(x => sRoads_EPointIds.Contains(x.startpoint_id)).ToList();
|
||||
if (subRoads?.Count > 0 && !isVisited[sPointId])
|
||||
{
|
||||
isVisited[sPointId] = true;
|
||||
for (int i = 0; i < subRoads.Count; i++)
|
||||
{
|
||||
var sIdx = subRoads[i].startpoint_id;
|
||||
if (!isVisited[sIdx])
|
||||
{
|
||||
DpFunc(roads, subRoads, pointIds, isVisited, sIdx, ePointId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user