protected void Page_Load(object sender, EventArgs e) { ArrayList nodeList = new ArrayList(); //Node aNode = new Node("北京"); //nodeList.Add(aNode); //aNode.EdgeList.Add(new Edge("北京", "上海", 20)); //aNode.EdgeList.Add(new Edge("北京", "武汉", 40)); Node bNode = new Node("上海"); nodeList.Add(bNode); bNode.EdgeList.Add(new Edge("上海", "北京", 20)); bNode.EdgeList.Add(new Edge("上海", "武汉", 70)); Node cNode = new Node("武汉"); nodeList.Add(cNode); cNode.EdgeList.Add(new Edge("武汉", "北京", 40)); cNode.EdgeList.Add(new Edge("武汉", "上海", 70)); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; result = planner.Paln(nodeList, "武汉", "上海"); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write("上海"); Response.Write("<br />"); planner = null; }
protected void Page_Load(object sender, EventArgs e) { ArrayList nodeList = new ArrayList();//结点的序列 //***************** A Node 北京 ******************* Node aNode = new Node("北京"); nodeList.Add(aNode); aNode.EdgeList.Add(new Edge("北京", "上海", 20)); aNode.EdgeList.Add(new Edge("北京", "武汉", 40)); //***************** B Node 上海******************* Node bNode = new Node("上海"); nodeList.Add(bNode); bNode.EdgeList.Add(new Edge("上海", "武汉", 70)); bNode.EdgeList.Add(new Edge("上海", "北京", 20)); //***************** D Node ******************* Node dNode = new Node("武汉"); nodeList.Add(dNode); dNode.EdgeList.Add(new Edge("武汉", "上海", 70)); dNode.EdgeList.Add(new Edge("武汉", "北京", 40)); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; //Paln函数是核心函数,首先将所有节点喂给模型,然后输入起点和终点,返回最优路径 result = planner.Paln(nodeList, "武汉", "上海"); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write("上海"); Response.Write("<br>"); planner = null; }
protected void Page_Load(object sender, EventArgs e) { string pointA = "北京"; string pointB = "上海"; ArrayList nodeList = new ArrayList(); Node aNode = new Node("北京"); nodeList.Add(aNode); aNode.EdgeList.Add(new Edge("北京", "上海", 20)); aNode.EdgeList.Add(new Edge("北京", "武汉", 60)); Node dNode = new Node("武汉"); nodeList.Add(dNode); dNode.EdgeList.Add(new Edge("武汉", "北京", 40)); //string output = JsonConvert.SerializeObject(nodeList); //File.WriteAllText(@Server.MapPath("~/data/ExampleSQL.json"), output); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; result = planner.Paln(nodeList, pointA, pointB); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write(pointB); Response.Write("</br>"); planner = null; }
protected void BtnDijkstra_Click(object sender, EventArgs e) { string strPointAID, strPointBID; strPointAID = DdlPointA.SelectedValue; strPointBID = DdlPointB.SelectedValue; if (strPointAID.Equals(strPointBID)) { Response.Write("距离为: 0<br />路径: " + strPointAID); return; } try { // 调包, 运行Dijkstra算法 RoutePlanner planner = new RoutePlanner(); RoutePlanResult planResult = planner.Paln(arrayNodes, strPointAID, strPointBID); if (planResult.getWeight() < 100000) { Response.Write("距离为: " + planResult.getWeight().ToString()); PrintRouteResult(planResult); Response.Write(strPointBID + "<br />"); } else { Response.Write("无路径<br />"); } planner = null; } catch (Exception Ex) { Response.Write(Ex.Message); } }
public static void LogFailure(GameObject routingObject, RouteAction.FailureExplanation explanation, RoutePlanResult planResult, string errorText) { RoutingComponent.mnNumDoRouteFailures += (ulong)0x1L; if (RoutingComponent.mbLogFailures) { Common.StringBuilder msg = new Common.StringBuilder("Explanation: " + explanation); msg += Common.NewLine + "Result: " + planResult; msg += Common.NewLine + "Error: " + errorText; if (routingObject.LotCurrent != null) { msg += Common.NewLine + "Address A: " + routingObject.LotCurrent.Address; } Sim sim = routingObject as Sim; if (sim != null) { InteractionInstance currentInteraction = sim.CurrentInteraction; InteractionInstance nextInteraction = sim.InteractionQueue.GetNextInteraction(); if (((currentInteraction != null) && (currentInteraction.Target != null)) && (currentInteraction.Target.LotCurrent != null)) { msg += Common.NewLine + "Address B: " + currentInteraction.Target.LotCurrent.Address; } if (((nextInteraction != null) && (nextInteraction.Target != null)) && (nextInteraction.Target.LotCurrent != null)) { msg += Common.NewLine + "Address C: " + nextInteraction.Target.LotCurrent.Address; } } Common.DebugNotify(msg, sim); } }
public void SetGoPiont(string GoPoint) { string BeginP = ""; string EndP = ""; string ReBack = ""; BeginP = GetValue(LocalPoint).Replace("_", ""); if (LocalPoint.Trim() == "") { MessageBox.Show("无当前坐标!"); return; } if (BeginP != GoPoint) { BeginP = "A" + BeginP; EndP = "A" + GoPoint; } RoutePlanResult Tresult = planner.Paln(_ComData.nodeList, BeginP, EndP); foreach (string strln in Tresult.getPassedNodeIDs()) { ReBack += "_" + strln; } string PassStr = ReBack + "_" + EndP; SetTask(PassStr.Replace("A", "")); }
protected void Page_Load(object sender, EventArgs e) { ArrayList nodeList = new ArrayList(); Node a = new Node("A"); nodeList.Add(a); a = new Node("A"); nodeList.Add(a); a.EdgeList.Add(new Edge("A", "B", 1)); a = new Node("B"); nodeList.Add(a); a.EdgeList.Add(new Edge("B", "C", 1)); a = new Node("A"); nodeList.Add(a); a.EdgeList.Add(new Edge("A", "B", 1)); a = new Node("C"); nodeList.Add(a); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; //Paln 函数是核心函数,首先将所有节点喂给模型,然后输入起点和终点,返回最优路径 result = planner.Paln(nodeList, "A", "C"); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write("C"); //Response.Write("上海"); //Response.Write("<br>"); planner = null; //***************** A Node 北京 ******************* //Node aNode = new Node("北京"); //nodeList.Add(aNode); //aNode.EdgeList.Add(new Edge("北京", "上海", 20)); //aNode.EdgeList.Add(new Edge("北京", "武汉", 40)); }
protected void btnStart_Click(object sender, EventArgs e) { if (ddlStart.SelectedValue == "0" || ddlEnd.SelectedValue == "0") { Response.Write("<script>alert('Didn't Choose!');</script>"); return; } if (ddlStart.SelectedValue == ddlEnd.SelectedValue) { lblResult.Text = "There is no need to walk!"; return; } SQLHelper sh = new SQLHelper(); DataSet dsNodeList = new DataSet(); string sqlNodeList = ("SELECT [Location1] AS [Location] FROM [dbo].[TblLocation] UNION SELECT [Location2] FROM [dbo].[TblLocation]"); sh.RunSQL(sqlNodeList, ref dsNodeList); int nodeNumber = dsNodeList.Tables[0].Rows.Count; Node[] node = new Node[nodeNumber]; ArrayList nodeList = new ArrayList(); for (int i = 0; i < nodeNumber; i++) { node[i] = new Node(dsNodeList.Tables[0].Rows[i][0].ToString()); nodeList.Add(node[i]); } DataSet dsPath = new DataSet(); for (int i = 0; i < nodeNumber; i++) { string sqlNodePath = string.Format("SELECT [Location2] AS Location,[distance] FROM [dbo].[TblLocation] WHERE [Location1] = '{0}' UNION SELECT [Location1] AS Location,[distance] FROM [dbo].[TblLocation] WHERE [Location2] = '{0}' ", node[i].ID.ToString()); sh.RunSQL(sqlNodePath, ref dsPath); for (int j = 0; j < dsPath.Tables[0].Rows.Count; j++) { node[i].EdgeList.Add(new Edge(node[i].ID.ToString(), dsPath.Tables[0].Rows[j][0].ToString(), double.Parse(dsPath.Tables[0].Rows[j][1].ToString()))); } dsPath = null; } sh.Close(); sh = null; RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = planner.Paln(nodeList, ddlStart.SelectedValue, ddlEnd.SelectedValue); lblResult.Text = "Distance:" + result.getWeight().ToString() + " Route:" + DetailedRoute(result); planner = null; }
private void printRouteResult(RoutePlanResult result) { Response.Write("<br />路径"); string[] tmp = result.getPassedNodeIDs(); for (int i = 0; i < tmp.Length; i++) { Response.Write(tmp[i] + "--"); } }
private void printRouteResult(RoutePlanResult _result) { Response.Write("</br>路径:"); //获取最短路径结果中,所有的节点 string[] tmp = _result.getPassedNodeIDs(); for (int i = 0; i < tmp.Length; i++) { Response.Write(tmp[i] + "-->"); } }
private void printRouteResult(RoutePlanResult _result) { string[] tmp = _result.getPassedNodeIDs(); for (int i = 0; i < tmp.Length; i++) { Response.Write(tmp[i] + "-->"); } Response.Write(ddlEnd.SelectedValue); Response.Write("<br>"); }
private void button2_Click(object sender, EventArgs e) { if (comboBox2.Text == comboBox4.Text) { MessageBox.Show("不能同在一个地标上!"); return; } LocalPoint = this.comboBox4.Text; string Fction = ""; string BeginP = "A14"; string EndP = "A11"; string ReBack = ""; if (LocalPoint.Trim() == "") { MessageBox.Show("无当前坐标!"); return; } if (LocalPoint != comboBox2.Text) { BeginP = "A" + LocalPoint; EndP = "A" + comboBox2.Text; } RoutePlanResult Tresult = planner.Paln(_ComData.nodeList, BeginP, EndP); foreach (string strln in Tresult.getPassedNodeIDs()) { Fction += ">" + strln; ReBack += "_" + strln; } Fction = Fction + "->" + EndP; PassStr = ReBack + "_" + EndP; if (_hts.ContainsKey(comboBox5.Text)) { if (MessageBox.Show("已经设置过AGV#" + comboBox5.Text + ",是否要覆盖之前设置", "提示!", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { _hts[comboBox5.Text] = PassStr; return; } else { return; } } _hts.Add(comboBox5.Text, PassStr); this.richTextBox1.Text += "\nAGV#编号: " + comboBox5.Text + " 已设置,"; richTextBox1.Text += " 路径:" + Fction.Replace("A", ""); DevID = comboBox5.Text; }
private string DetailedRoute(RoutePlanResult result) { string[] point = result.getPassedNodeIDs(); string route = ""; for (int i = 0; i < point.Length; i++) { route += point[i] + "--->"; } route += ddlEnd.SelectedValue; return(route); }
public void SetCall() { string Fction = ""; string BeginP = "A14"; string EndP = "A11"; RoutePlanResult Tresult = planner.Paln(_ComData.nodeList, BeginP, EndP); foreach (string strln in Tresult.getPassedNodeIDs()) { Fction += strln; } CreateNode(Fction + EndP); }
static void Main(string[] args) { // 构造一个 图. Graph graph = new Graph(); graph.Init(); // 最短路径计算. RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = planner.Paln(graph.NodeList, "A", "D"); // 输出结果. Console.WriteLine(result.ToString()); Console.ReadLine(); }
protected override bool InitialPrep(CastFireBlastTerrainEx ths, bool twoPerson, IMagicalDefinition definition, MagicControl control, bool spellCastingSucceeded, bool spellCastingEpiclyFailed) { Vector3 targetPosition = ths.GetTargetPosition(); Route r = ths.Actor.CreateRoute(); RoutePlanResult result = r.PlanToPointRadius(targetPosition, kRoutingDistance, RouteOrientationPreference.TowardsObject, LotManager.GetLotAtPoint(targetPosition).LotId, new int[] { World.GetRoomId(targetPosition) }); if (!result.Succeeded() || World.IsInPool(result.mDestination)) { ths.Actor.PlayRouteFailure(); return(false); } if (!ths.Actor.DoRoute(r)) { return(false); } return(true); }
/// <summary> /// 从源星球到目标星球的最短路径(待优化:保存源星球的最短路径表,下次寻找不必再次运算算法) /// </summary> /// <param name="StartStar">源星球</param> /// <param name="EndStar">目标星球</param> /// <returns>所有经过的星球(包括目标星球)</returns> public static RoutePlanResult Plan(UnitStar StartStar, UnitStar EndStar) { RoutePlanResult result = new RoutePlanResult(); //在调用最短路径算法前, Node.CheckNodeCanReach先判断目标节点是否在源节点移动半径内,是的话直接返回源节点(两点之间,直线最短) if (StartStar.CheckStarReachByDistance(EndStar) == true) { result.PassedStars.Add(StartStar); result.PassedStars.Add(EndStar); result.Weight = StartStar.GetTargetStarDistance(EndStar); } else { RoutePlanner planner = new RoutePlanner(); result = planner.Paln(MogoWorld.m_dataMapManager.GetStarList(), StartStar.UnitId, EndStar.UnitId); result.PassedStars.Add(EndStar); planner = null; } return(result); }
/// <summary> /// 从PlanCourse表中取出目标节点的PassedPath,这个PassedPath即是规划结果 /// </summary> /// <returns></returns> private RoutePlanResult GetResult(PlanCourse planCourse, string destID) { PassedPath pPath = planCourse[destID]; if (pPath.Weight == int.MaxValue) { RoutePlanResult result1 = new RoutePlanResult(null, int.MaxValue); return(result1); } Node[] passedNodeIDs = new Node[pPath.PassedNodeList.Count]; for (int i = 0; i < passedNodeIDs.Length; i++) { passedNodeIDs[i] = pPath.PassedNodeList[i]; } RoutePlanResult result = new RoutePlanResult(passedNodeIDs, pPath.Weight); return(result); }
private void button3_Click(object sender, EventArgs e) { if (comboBox5.Text == comboBox4.Text) { MessageBox.Show("不能同在一个地标上!"); return; } LocalPoint = this.comboBox4.Text; this.richTextBox1.Text += "\n AGV#" + comboBox2.Text + ">> 起始地标: " + LocalPoint + " 开往目的地标:" + comboBox5.Text + " 已设定。"; string Fction = ""; string BeginP = "A14"; string EndP = "A11"; string ReBack = ""; if (LocalPoint.Trim() == "") { MessageBox.Show("无当前坐标!"); return; } if (LocalPoint != comboBox5.Text) { BeginP = "A" + LocalPoint; EndP = "A" + comboBox5.Text; } RoutePlanResult Tresult = planner.Paln(_ComData.nodeList, BeginP, EndP); foreach (string strln in Tresult.getPassedNodeIDs()) { Fction += "->" + strln; ReBack += "_" + strln; } Fction = Fction + "->>" + EndP; PassStr = ReBack + "_" + EndP; richTextBox1.Text += " 路径:" + Fction.Replace("A", ""); DevID = comboBox2.Text; }
protected void btnQuery_Click(object sender, EventArgs e) { #region string startSta = this.ddlBegin.SelectedValue;//获取始发站 string targetSta = this.ddlEnd.SelectedValue;//获取终点站 string strOption = this.ddlOptions.SelectedValue;//获取查询选项 //验证用户选择的路线是否符合查询要求 string tmpRet = ""; if (bizPlanPath.ValideData(startSta, targetSta, ref tmpRet) == false) { ClientScript.RegisterClientScriptBlock(this.GetType(), "Message", "<script>alert('" + tmpRet + "');</script>"); return; } //调用业务外观进行路线查询 ret=bizPlanPath.GetPlanPath(startSta,targetSta,strOption); if(ret==null) { ClientScript.RegisterClientScriptBlock(this.GetType(), "Message", "<script>alert('没有找到合适的路线!');</script>"); return; } //显示标记出现路线后的地铁线路 string sessionId = new Guid().ToString(); Session[sessionId] = ret; ViewState["currSid"] = sessionId; myMap.ImageUrl = "GetMap.aspx?curSessionId=" + sessionId; //设置UI元素 this.myMap.Visible = true;//默认设置地铁路线可见 this.PnlXCView.Visible = false;//默认设置行程表格视图不可见 this.rdoView.SelectedIndex = 0;//设置预览视图和行程视图的单选钮状态,即选中预览视图 #endregion this.hdUseTime.Value = ret.weight.ToString(); this.hdMapData.Value = this.GetMapData(ret.passedNodeIDs, ret.passedNodeIDs[0]); }
//从PlanCourse表中取出目标节点的PassedPath,这个PassedPath即是规划结果 private RoutePlanResult GetResult(PlanCourse planCourse, int destID) { PassedPath pPath = planCourse[destID]; if (pPath.Weight == int.MaxValue) { RoutePlanResult result1 = new RoutePlanResult(); result1.Weight = int.MaxValue; return(result1); } List <UnitStar> passedStars = new List <UnitStar>(); for (int i = 0; i < pPath.PassedIDList.Count; i++) { passedStars.Add(MogoWorld.m_dataMapManager.GetUnitStarById(pPath.PassedIDList[i])); } RoutePlanResult result = new RoutePlanResult(); result.PassedStars = passedStars; result.Weight = pPath.Weight; return(result); }
protected void Button1_Click(object sender, EventArgs e) { RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; result = planner.Paln(nodeList, ddlStart.SelectedValue, ddlEnd.SelectedValue); //当路径的权值返回是double的最大值,就认为,两点间的距离是正无穷,也就是不通的 double aim = Math.Abs(result.getWeight() - double.MaxValue); string finalpath = string.Format("{0}到{1}的路径是:", ddlStart.SelectedValue, ddlEnd.SelectedValue); Response.Write(finalpath); if (aim <= 0) { Response.Write("距离为正无穷"); } else { Response.Write("距离为" + result.getWeight()); //输出路径 printRouteResult(result); } planner = null; }
private static void Reroute(Route r, AncientPortal closest, AncientPortal destination) { Sim target = r.Follower.Target as Sim; Vector3 currentStartPoint = r.GetCurrentStartPoint(); float distanceRemaining = r.GetDistanceRemaining(); Common.StringBuilder msg = new Common.StringBuilder(); msg.Append("AncientPortal Reroute: " + target.FullName); Route routeToPortal = target.CreateRoute(); routeToPortal.SetOption(Route.RouteOption.EnableSubwayPlanning, false); routeToPortal.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false); routeToPortal.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar)); routeToPortal.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller)); routeToPortal.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller)); routeToPortal.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller)); Vector3 slotPosition = closest.GetSlotPosition(closest.GetRoutingSlots()[0]); Vector3 slotFoward = closest.GetForwardOfSlot(closest.GetRoutingSlots()[0]); Vector3 farPosition = new Vector3(slotPosition); farPosition.x -= slotFoward.x / 4f; farPosition.y -= slotFoward.y / 4f; RoutePlanResult result = routeToPortal.PlanToPoint(farPosition); msg.Append(Common.NewLine + "Result: " + result); if (result.Succeeded()) { msg.Append(Common.NewLine + "D" + Common.NewLine + Routes.RouteToString(routeToPortal)); Route portalRoute = target.CreateRoute(); portalRoute.SetOption(Route.RouteOption.EnableSubwayPlanning, false); portalRoute.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false); portalRoute.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar)); portalRoute.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller)); portalRoute.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller)); portalRoute.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller)); result = portalRoute.PlanToPointFromPoint(slotPosition, farPosition); msg.Append(Common.NewLine + "Result: " + result); if (result.Succeeded()) { PathData portalData = new PathData(); portalData.PathType = PathType.PortalPath; portalData.ObjectId = closest.ObjectId; portalData.PortalStartPos = slotPosition; portalRoute.SetPathData(ref portalData); msg.Append(Common.NewLine + "A" + Common.NewLine + Routes.RouteToString(portalRoute)); slotPosition = destination.GetSlotPosition(destination.GetRoutingSlots()[0]); r.SetOption(Route.RouteOption.EnableSubwayPlanning, false); if (!r.ReplanFromPoint(slotPosition).Succeeded()) { r.ReplanFromPoint(currentStartPoint); } else if ((routeToPortal.GetDistanceRemaining() + r.GetDistanceRemaining()) < (distanceRemaining + SimRoutingComponent.kDistanceMustSaveInOrderToUseSubway)) { AncientPortalComponent.AddTargetPortal(target, destination); msg.Append(Common.NewLine + "B" + Common.NewLine + Routes.RouteToString(r)); r.InsertRouteSubPathsAtIndex(0x0, portalRoute); r.InsertRouteSubPathsAtIndex(0x0, routeToPortal); msg.Append(Common.NewLine + "C" + Common.NewLine + Routes.RouteToString(r)); r.SetOption(Route.RouteOption.EnableSubwayPlanning, true); } else { r.ReplanFromPoint(currentStartPoint); } } } Common.DebugNotify(msg, target); Common.DebugWriteLog(msg); }
private void btnRW_Click(object sender, EventArgs e) { Node aNode = new Node("A"); nodeList.Add(aNode); Edge aEdge1 = new Edge(); aEdge1.StartNodeID = aNode.ID; aEdge1.EndNodeID = "B"; aEdge1.Weight = 10; aNode.EdgeList.Add(aEdge1); Node bNode = new Node("B"); nodeList.Add(bNode); Edge bEdge1 = new Edge(); bEdge1.StartNodeID = bNode.ID; bEdge1.EndNodeID = "C"; bEdge1.Weight = 5; bNode.EdgeList.Add(bEdge1); Edge bEdge2 = new Edge(); bEdge2.StartNodeID = bNode.ID; bEdge2.EndNodeID = "D"; bEdge2.Weight = 5; bNode.EdgeList.Add(bEdge2); Node cNode = new Node("C"); nodeList.Add(cNode); Edge cEdge1 = new Edge(); cEdge1.StartNodeID = cNode.ID; cEdge1.EndNodeID = "D"; cEdge1.Weight = 5; cNode.EdgeList.Add(cEdge1); Edge cEdge2 = new Edge(); cEdge2.StartNodeID = cNode.ID; cEdge2.EndNodeID = "B"; cEdge2.Weight = 5; cNode.EdgeList.Add(cEdge2); Edge cEdge3 = new Edge(); cEdge3.StartNodeID = cNode.ID; cEdge3.EndNodeID = "F"; cEdge3.Weight = 10; cNode.EdgeList.Add(cEdge3); Node dNode = new Node("D"); nodeList.Add(dNode); Edge dEdge1 = new Edge(); dEdge1.StartNodeID = dNode.ID; dEdge1.EndNodeID = "B"; dEdge1.Weight = 5; dNode.EdgeList.Add(dEdge1); Edge dEdge2 = new Edge(); dEdge2.StartNodeID = dNode.ID; dEdge2.EndNodeID = "C"; dEdge2.Weight = 5; dNode.EdgeList.Add(dEdge2); Edge dEdge3 = new Edge(); dEdge3.StartNodeID = dNode.ID; dEdge3.EndNodeID = "E"; dEdge3.Weight = 10; dNode.EdgeList.Add(dEdge3); Node eNode = new Node("E"); nodeList.Add(eNode); Edge eEdge1 = new Edge(); eEdge1.StartNodeID = eNode.ID; eEdge1.EndNodeID = "D"; eEdge1.Weight = 10; eNode.EdgeList.Add(eEdge1); Node fNode = new Node("F"); nodeList.Add(fNode); Edge fEdge1 = new Edge(); fEdge1.StartNodeID = fNode.ID; fEdge1.EndNodeID = "C"; fEdge1.Weight = 10; fNode.EdgeList.Add(fEdge1); Edge fEdge2 = new Edge(); fEdge2.StartNodeID = fNode.ID; fEdge2.EndNodeID = "H"; fEdge2.Weight = 5; fNode.EdgeList.Add(fEdge2); Edge fEdge3 = new Edge(); fEdge3.StartNodeID = fNode.ID; fEdge3.EndNodeID = "G"; fEdge3.Weight = 5; fNode.EdgeList.Add(fEdge3); Node gNode = new Node("G"); nodeList.Add(gNode); Edge gEdge1 = new Edge(); gEdge1.StartNodeID = gNode.ID; gEdge1.EndNodeID = "F"; gEdge1.Weight = 5; gNode.EdgeList.Add(gEdge1); Edge gEdge2 = new Edge(); gEdge2.StartNodeID = gNode.ID; gEdge2.EndNodeID = "I"; gEdge2.Weight = 6; gNode.EdgeList.Add(gEdge2); Node hNode = new Node("H"); nodeList.Add(hNode); Edge hEdge1 = new Edge(); hEdge1.StartNodeID = hNode.ID; hEdge1.EndNodeID = "F"; hEdge1.Weight = 5; hNode.EdgeList.Add(hEdge1); Edge hEdge2 = new Edge(); hEdge2.StartNodeID = hNode.ID; hEdge2.EndNodeID = "I"; hEdge2.Weight = 5; hNode.EdgeList.Add(hEdge2); Node iNode = new Node("I"); nodeList.Add(iNode); Edge iEdge1 = new Edge(); iEdge1.StartNodeID = iNode.ID; iEdge1.EndNodeID = "H"; iEdge1.Weight = 5; iNode.EdgeList.Add(iEdge1); Edge iEdge2 = new Edge(); iEdge2.StartNodeID = iNode.ID; iEdge2.EndNodeID = "G"; iEdge2.Weight = 6; iNode.EdgeList.Add(iEdge2); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = planner.Paln(nodeList, "E", "C"); }
public static RouteAction.ActionResult PerformAction(ObstacleEncounteredRouteInterruptAction ths) { try { ths.mRoutingSim.SimRoutingComponent.EnableDynamicFootprint(); ths.mRoutingSim.SimRoutingComponent.StopPushImmunity(); if ((ths.mRoutingSim.SimRoutingComponent.UsingStroller && (ths.mRoutingSim.CarryingChildPosture != null)) && (ths.mRoutingSim.CarryingChildPosture.Stroller != null)) { ths.mRoutingSim.CarryingChildPosture.Stroller.SetPosition(ths.mRoutingSim.CarryingChildPosture.Stroller.Position); } bool option = ths.mInterruptedPath.GetOption(Route.RouteOption.BlockedByPeople); ths.mInterruptedPath.SetOption(Route.RouteOption.BlockedByPeople, true); if (ths.mbForceInitialReplan) { RoutePlanResult result = ths.mInterruptedPath.Replan(); if (!result.Succeeded()) { GameObject obj2 = new ObjectGuid(result.mBlockerObjectId).ObjectFromId <GameObject>(); ths.mRoutingSim.SimRoutingComponent.PlayRouteFailureIfAppropriate(obj2); return(RouteAction.ActionResult.Terminate); } } /* This is duplicated in StandAndWaitController, I believe it is an EA error since there is no "Exit" * StateMachineClient client = StateMachineClient.Acquire(ths.mRoutingSim, "StandAndWait"); * client.SetActor("x", ths.mRoutingSim); * client.SetParameter("isMermaid", OccultMermaid.IsMatureMermaidAndWearingTail(base.mRoutingSim)); * client.EnterState("x", "Enter"); */ SpeedTrap.Sleep(); ths.mnCheckFrequency = 0x1; ths.mnCheckOffset = 0x0; try { StandAndWaitController controller = new StandAndWaitController(); controller.AllowZeroCycle = ths.mbAllowZeroCycle; controller.Duration = SimRoutingComponent.DefaultStandAndWaitDuration; controller.OnCycle = ths.StandAndWaitCycleHandler; controller.Run(ths.mRoutingSim); } catch (SacsErrorException e) { Common.DebugException("ObstacleEncounteredRouteInterruptActionEx:PerformAction", e); } ths.mRoutingSim.SimRoutingComponent.DisableDynamicFootprint(); if (!ths.mbElectedToExit) { ths.mReturnValue = RouteAction.ActionResult.Terminate; } if (ths.mReturnValue == RouteAction.ActionResult.Terminate) { int numObstacles = 0x0; int numPushableObstacles = 0x0; int numWorldObstacles = 0x0; int numStaticObstacles = 0x0; int numReplannableObstacles = 0x0; ObjectGuid[] guidArray = ths.CollectObstacles(ths.mRoutingSim, ref numObstacles, ref numPushableObstacles, ref numReplannableObstacles, ref numStaticObstacles, ref numWorldObstacles); int num6 = numObstacles - numWorldObstacles; if (numObstacles > 0x0) { if ((ths.mRoutingSim.LotCurrent != null) && !ths.mRoutingSim.LotCurrent.IsWorldLot) { if ((num6 == 0x0) && (numWorldObstacles > 0x0)) { ths.mRoutingSim.SimRoutingComponent.StartIgnoringObstacles(); return(RouteAction.ActionResult.ContinueAndFollowPath); } else if ((num6 >= 0x3) && (Sims3.Gameplay.Queries.CountObjects <Sim>(ths.mRoutingSim.Position, 1f) >= 0x4)) { ths.mRoutingSim.SimRoutingComponent.StartIgnoringObstacles(); return(RouteAction.ActionResult.ContinueAndFollowPath); } } else if (numWorldObstacles > 0x0) { ths.mRoutingSim.SimRoutingComponent.StartIgnoringObstacles(); return(RouteAction.ActionResult.ContinueAndFollowPath); } } else { ths.mRoutingSim.SimRoutingComponent.StartPushImmunity(SimRoutingComponent.OnRouteStartedImmuneToPushesDuration); } if ((!ths.mRoutingSim.HasExitReason(ExitReason.CancelExternal | ExitReason.MidRoutePushRequested) && ths.mInterruptedPath.DoRouteFail) && !ths.mInterruptedPath.PlanResult.Succeeded()) { foreach (ObjectGuid guid in guidArray) { GameObject obj3 = guid.ObjectFromId <GameObject>(); if (ths.mRoutingSim.SimRoutingComponent.PlayRouteFailureIfAppropriate(obj3)) { break; } } } } ths.mInterruptedPath.SetOption(Route.RouteOption.BlockedByPeople, option); return(ths.mReturnValue); } catch (ResetException) { throw; } catch (Exception e) { Common.Exception("ObstacleEncounteredRouteInterruptActionEx:PerformAction", e); throw; } }
//进行计算时间上可行的第一个空间位置 private void button4_Click(object sender, EventArgs e) { try { if (comboBox1.Text == "") { MessageBox.Show("请输入应急资源仓库数据", "输入应急资源仓库数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox2.Text == "") { MessageBox.Show("请输入道路网络数据", "输入道路网络数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox3.Text == "") { MessageBox.Show("请输入污染物扩散模拟过程数据", "输入污染物扩散模拟过程数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (textBox1.Text == "") { MessageBox.Show("请输入应急处置工程建设时间(单位:分钟):", "输入应急处置工程建设时间(单位:分钟):", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox4.Text == "") { MessageBox.Show("请输出可供选择首个应急处置空间位置", "输出可供选择首个应急处置空间位置", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { int row = 0, column = 0; double X = 0.0, Y = 0.0; double pixelvalue = 0.0; IRasterLayer pRasterLayer = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text); IFeatureLayer pFeatureLayerDepot = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text); IFeatureLayer pFeatureLayerroad = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text); //获取污染物模拟河流的外包络线 IRaster pRaster = pRasterLayer.Raster; IRasterProps pRasterprops = pRaster as IRasterProps; IEnvelope pEnvelope = pRasterprops.Extent; IPoint p1 = new PointClass(); IPoint p2 = new PointClass(); IPoint p3 = new PointClass(); IPoint p4 = new PointClass(); p1 = pEnvelope.UpperLeft; p2 = pEnvelope.LowerLeft; p3 = pEnvelope.LowerRight; p4 = pEnvelope.UpperRight; IPointCollection pointCollection = new PolygonClass(); object missing = Type.Missing; pointCollection.AddPoint(p1, ref missing, ref missing); pointCollection.AddPoint(p2, ref missing, ref missing); pointCollection.AddPoint(p3, ref missing, ref missing); pointCollection.AddPoint(p4, ref missing, ref missing); pointCollection.AddPoint(p1, ref missing, ref missing); IPolygon polygon = (IPolygon)pointCollection; IGeometry pGeometry = new PolygonClass(); pGeometry = polygon as IGeometry; //获取应急资源仓库到达各个节点的最短路径 List <IFeature> listFeature = new List <IFeature>(); listFeature = GetPolygonFeatureList(pFeatureLayerroad, pGeometry); RoutePlanResult startNoderesult = null, EndNoderesult = null, minStartNodeResult = null, minEndNodeResult = null; DijkstraDepotToAllNodeMethod path = new DijkstraDepotToAllNodeMethod(); path.InitializationRoadNetwork(pFeatureLayerDepot); List <PlanCourse> resultplancourse = path.DepotToAllNode(); RasterManagement.GetRasterCount(pRasterLayer, ref row, ref column); double[] desttime = new double[2]; int sign = 0; //IFeature pFeature = null; string strStartID = null, strEndID = null; double time = 0.0; double returnX = 0.0, returnY = 0.0; double pFrompointToOutpointLength = 0.0, pOutpointToEndpointLength = 0.0; IPolyline polyline = new PolylineClass(); //对污染物模拟栅格从[0,0]进行循环,选取从时间上作为应急处置空间位置的可行性的点 for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { pixelvalue = Convert.ToDouble(RasterManagement.GetPixelValue(pRasterLayer, 0, j, i)); if (pixelvalue != 0) { IFeature pFeature = null; RasterManagement.NumbercovertXY(pRasterLayer, ref X, ref Y, j, i); IPoint point = new PointClass(); point.PutCoords(X, Y); IPoint ppoint = new PointClass(); GetMindistanceandpoint(point, listFeature, ref returnX, ref returnY, ref pFeature, ref pFrompointToOutpointLength); ppoint.PutCoords(returnX, returnY); strStartID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField("StartNodeI"))); strEndID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField("EndNodeID"))); time = Convert.ToDouble(pFeature.get_Value(pFeature.Fields.FindField("Minutes"))); polyline = pFeature.Shape as IPolyline; pOutpointToEndpointLength = polyline.Length - pFrompointToOutpointLength; //获取应急仓库到达应急处置点最短时间的点 minStartNodeResult = startNoderesult = RoutePlanner.GetResult(resultplancourse[0], strStartID); minEndNodeResult = EndNoderesult = RoutePlanner.GetResult(resultplancourse[0], strEndID); for (int m = 1; m < resultplancourse.Count; m++) { startNoderesult = RoutePlanner.GetResult(resultplancourse[m], strStartID); EndNoderesult = RoutePlanner.GetResult(resultplancourse[m], strEndID); if (minStartNodeResult.WeightValues > startNoderesult.WeightValues) { minStartNodeResult = startNoderesult; } if (minEndNodeResult.WeightValues > EndNoderesult.WeightValues) { minEndNodeResult = EndNoderesult; } } desttime[0] = time * (pFrompointToOutpointLength / (pFrompointToOutpointLength + pOutpointToEndpointLength)); desttime[1] = time - desttime[0]; //判断污染物到达该应急处置空间位置的时间是否大于应急资源调度时间与工程措施建设时间之和 if (minStartNodeResult.WeightValues + desttime[0] > minEndNodeResult.WeightValues + desttime[1]) { if ((minEndNodeResult.WeightValues + desttime[1] + Convert.ToDouble(textBox1.Text)) < pixelvalue) { List <IPoint> pointlist = new List <IPoint>(); pointlist.Add(point); SaveVector.pointtoFeatureLayer(comboBox4.Text, pointlist, pFeatureLayerDepot); sign = 1; break; } } else { if ((minStartNodeResult.WeightValues + desttime[0] + Convert.ToDouble(textBox1.Text)) < pixelvalue) { List <IPoint> pointlist = new List <IPoint>(); pointlist.Add(point); SaveVector.pointtoFeatureLayer(comboBox4.Text, pointlist, pFeatureLayerDepot); sign = 1; break; } } } } if (sign == 1) { break; } } MessageBox.Show("处理完毕!"); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }
protected void Button1_Click(object sender, EventArgs e) { //需要四个sql,sh,ds,dt,row string sqla1, sqla2, sqlb1, sqlb2; string ca = ""; string cb = ""; string start = ddl1.SelectedValue; string end = ddl2.SelectedValue; SQLHelper sha1 = new SQLHelper(); SQLHelper sha2 = new SQLHelper(); SQLHelper shb1 = new SQLHelper(); SQLHelper shb2 = new SQLHelper(); DataSet dsa1 = new DataSet(); DataSet dsb1 = new DataSet(); DataTable dta1, dta2, dtb1, dtb2; DataRow[] ra1, ra2, rb1, rb2; ArrayList nodeList = new ArrayList(); //思路:遍历A,对A的每一个城市,遍历所有路径;然后遍历B中不在A中的城市,同样遍历路径 //介于debug次数过多,把快捷的debug方法写在这里提醒自己:通过response.write监视nodelist的录入 sqla1 = "select PointA from students.dbo.tblDistance group by PointA"; sha1.RunSQL(sqla1, ref dsa1); dta1 = dsa1.Tables[0]; ra1 = dta1.Select("PointA is not null"); sha1.Close(); for (int i = 0; i <= dta1.Rows.Count - 1; i++) { ca = ra1[i]["PointA"].ToString(); Node a = new Node(ca); nodeList.Add(a); DataSet dsa2 = new DataSet(); //dsa2、dsb2一定要在for循环内反复声明,以清空set内存;否则,新ref到的数据会加入到Tables[0]中而非替换之 sqla2 = string.Format("select PointA,PointB,Distance from students.dbo.tblDistance where PointA='{0}' group by PointA,PointB,Distance", ca); sha2.RunSQL(sqla2, ref dsa2); dta2 = dsa2.Tables[0]; ra2 = dta2.Select("PointA is not null"); sha2.Close(); for (int j = 0; j <= dta2.Rows.Count - 1; j++) { cb = ra2[j]["PointB"].ToString(); a.EdgeList.Add(new Edge(ca, cb, double.Parse(ra2[j]["Distance"].ToString()))); } } sqlb1 = "select PointB from (select PointB from students.dbo.tblDistance group by PointB)B left join (select PointA from students.dbo.tblDistance group by PointA)A on A.PointA=B.PointB where PointA is null"; shb1.RunSQL(sqlb1, ref dsb1); dtb1 = dsb1.Tables[0]; rb1 = dtb1.Select("PointB is not null"); shb1.Close(); for (int i = 0; i <= dtb1.Rows.Count - 1; i++) { cb = rb1[i]["PointB"].ToString(); DataSet dsb2 = new DataSet(); sqlb2 = string.Format("select PointA,PointB,Distance from students.dbo.tblDistance where PointB='{0}' group by PointA,PointB,Distance", cb); shb2.RunSQL(sqlb2, ref dsb2); dtb2 = dsb2.Tables[0]; rb2 = dtb2.Select("PointB is not null"); shb2.Close(); Node b = new Node(cb); nodeList.Add(b); for (int j = 0; j <= dtb2.Rows.Count - 1; j++) { ca = rb2[j]["PointA"].ToString(); b.EdgeList.Add(new Edge(cb, ca, double.Parse(rb2[j]["Distance"].ToString()))); } } RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; if (start == end) { Response.Write("距离为0"); } else { result = planner.Paln(nodeList, start, end); if (result.getWeight() > 100000000) { Response.Write("两地无通路!"); } else { Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write(end + "</br>"); planner = null; } } }
private void GetPic() { Bitmap bitmap; Image img = global::CJia.Navigate.App.Properties.Resources.停车场2; _size = new Size(img.Size.Width, img.Size.Height); _backImage = new Bitmap(img, _size); bitmap = new Bitmap(img, _size); pictureBox1.Height = _size.Height; pictureBox1.Width = _size.Width; pictureBox1.Image = global::CJia.Navigate.App.Properties.Resources.停车场2; //string StartNo = CJia.Parking.Tools.ConfigHelper.GetAppStrings("StartNo"); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = planner.Paln(Graph.Nodelist, Start, ParkNo); planner = null; List <Point> pointList = result.PointList; DataTable dtPoint = CJia.DefaultPostgre.Query(CJia.Parking.Models.SqlTools.SqlQueryPointByPointNo, new object[] { ParkNo }); Point point = new Point(Convert.ToInt32(dtPoint.Rows[0]["point_X"]), Convert.ToInt32(dtPoint.Rows[0]["point_Y"])); pointList.Add(point); for (int i = 0; i < pointList.Count - 1; i++) { //DataTable dtPoint = CJia.DefaultPostgre.Query(CJia.Parking.Models.SqlTools.SqlQueryPointByPointNo, new object[] { nodeList[i].ToString() }); //Point point = new Point(Convert.ToInt32(dtPoint.Rows[0]["point_X"]), Convert.ToInt32(dtPoint.Rows[0]["point_Y"])); //listPoint.Add(point); if (result.PointList.Count > 1) { Bitmap bitmap1 = DrawLineInPicture(_backImage, pointList[i], pointList[i + 1], Color.Red, 5, DashStyle.Solid); Image myimage = Image.FromHbitmap(bitmap1.GetHbitmap()); pictureBox1.Image = myimage; } PictureBox picstart = new PictureBox(); //Image.FromFile("Images/起点.png"); picstart.Image = global::CJia.Navigate.App.Properties.Resources.起点; picstart.Width = 25; picstart.Height = 24; picstart.BackColor = System.Drawing.Color.Transparent; pictureBox1.Controls.Add(picstart); picstart.Location = new Point(pointList[0].X - 12, pointList[0].Y - 12); PictureBox picend = new PictureBox(); //Image.FromFile("Images/起点.png"); picend.Image = global::CJia.Navigate.App.Properties.Resources.终点; picend.Width = 25; picend.Height = 24; picend.BackColor = System.Drawing.Color.Transparent; pictureBox1.Controls.Add(picend); picend.Location = new Point(pointList[pointList.Count - 1].X - 12, pointList[pointList.Count - 1].Y - 12); } //for (int j = 0; j < listPoint.Count - 1; j++) //{ // Bitmap bitmap1 = DrawLineInPicture(_backImage, listPoint[j], listPoint[j + 1], Color.Red, 2, DashStyle.Solid); // Image myimage = Image.FromHbitmap(bitmap1.GetHbitmap()); // pictureBox1.Image = myimage; //} listPoint.Clear(); }
public static void LogFailure(GameObject routingObject, RouteAction.FailureExplanation explanation, RoutePlanResult planResult, string errorText) { RoutingComponent.mnNumDoRouteFailures += (ulong)0x1L; if (RoutingComponent.mbLogFailures) { Common.StringBuilder msg = new Common.StringBuilder("Explanation: " + explanation); msg += Common.NewLine + "Result: " + planResult; msg += Common.NewLine + "Error: " + errorText; if (routingObject.LotCurrent != null) { msg += Common.NewLine + "Address A: " + routingObject.LotCurrent.Address; } Sim sim = routingObject as Sim; if (sim != null) { InteractionInstance currentInteraction = sim.CurrentInteraction; InteractionInstance nextInteraction = sim.InteractionQueue.GetNextInteraction(); if (((currentInteraction != null) && (currentInteraction.Target != null)) && (currentInteraction.Target.LotCurrent != null)) { msg += Common.NewLine + "Address B: " + currentInteraction.Target.LotCurrent.Address; } if (((nextInteraction != null) && (nextInteraction.Target != null)) && (nextInteraction.Target.LotCurrent != null)) { msg += Common.NewLine + "Address C: " + nextInteraction.Target.LotCurrent.Address; } } Common.DebugNotify(msg, sim); } }
private void DispXCDetail() { if (ViewState["currSid"] == null) return; ret = (RoutePlanResult)Session[ViewState["currSid"].ToString()]; for (int i = this.tbData.Rows.Count - 1; i > 0; i--) { this.tbData.Rows.RemoveAt(i); } // string strOption = this.ddlOptions.SelectedValue; if (strOption == "2") this.txtPathDsc.Text = "换乘最少路线:"; else this.txtPathDsc.Text = "用时最短路线:"; if (this.ret != null) this.txtUseTime.Text = ret.weight.ToString(); //去掉重复的站点,因为在换乘路线查询算法中,如果有换乘发生,则会产生一些重复的换乘站的 //为了本算法的统一性,先去掉这些重复站点 IEnumerable passNodes = this.ret.passedNodeIDs.Distinct(); Queue paths = new Queue(); foreach (string v in passNodes) { paths.Enqueue(v); } Node priv, next; TableRow rowDef; Image img; Literal txt; double passTime = 0; Node tmpPriv; int passStationCount = 0; TableCell cel; priv = bizPlanPath.GetNode(paths.Dequeue().ToString()); tmpPriv = priv.Clone(); int row = 1; #region rowDef = new TableRow(); rowDef.Height = Unit.Pixel(25); this.SetRow(rowDef, row); this.tbData.Rows.Add(rowDef); //0 column rowDef.Cells.Add(new TableCell()); //1 rowDef.Cells.Add(new TableCell()); //2 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("station.png", 14, 15); cel.Controls.Add(img); rowDef.Cells.Add(cel); //3 column cel = new TableCell(); txt = new Literal(); txt.Text = "【" + priv.PathName + "】 " + priv.StaName; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //4 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; txt = new Literal(); txt.Text = "2元"; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //5 column cel = this.GetOperateColumn(ret.passedNodeIDs, priv.ID); cel.HorizontalAlign = HorizontalAlign.Center; rowDef.Cells.Add(cel); #endregion while (paths.Count > 0) { next = bizPlanPath.GetNode(paths.Peek().ToString()); if (paths.Count > 0) { tmpPriv = priv.Clone(); passTime += bizPlanPath.GetWeight(priv, next); priv = next.Clone(); paths.Dequeue(); passStationCount++; } if (paths.Count > 0 && tmpPriv.PathID != next.PathID) { row++; #region 正常路线 rowDef = new TableRow(); rowDef.Height = Unit.Pixel(25); this.SetRow(rowDef, row); this.tbData.Rows.Add(rowDef); //0 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("subway.png", 15, 14); cel.Controls.Add(img); rowDef.Cells.Add(cel); //1 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; txt = new Literal(); txt.Text = passTime.ToString() + "分"; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //2 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("A" + tmpPriv.PathID + ".png", 6, 25); cel.Controls.Add(img); rowDef.Cells.Add(cel); //3 column cel = new TableCell(); txt = new Literal(); txt.Text = "【" + tmpPriv.PathName + "】 " + tmpPriv.StaName + "(全程)方向(" + passStationCount.ToString() + ")"; ; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //4 column rowDef.Cells.Add(new TableCell()); //5 column rowDef.Cells.Add(new TableCell()); #endregion row++; #region 换乘路线 rowDef = new TableRow(); rowDef.Height = Unit.Pixel(25); this.SetRow(rowDef, row); this.tbData.Rows.Add(rowDef); //0 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("person.png", 15, 14); cel.Controls.Add(img); rowDef.Cells.Add(cel); //1 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; txt = new Literal(); txt.Text = bizPlanPath.GetWeight(tmpPriv, priv).ToString() + "分"; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //2 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("transfer.png", 13, 12); cel.Controls.Add(img); rowDef.Cells.Add(cel); //3 column cel = new TableCell(); txt = new Literal(); txt.Text = "【" + next.StaName + "】 (经由" + tmpPriv.PathName + "-" + tmpPriv.StaName + "方向)换乘"; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //4 column rowDef.Cells.Add(new TableCell()); //5 column cel = this.GetOperateColumn(ret.passedNodeIDs, next.ID); cel.HorizontalAlign = HorizontalAlign.Center; rowDef.Cells.Add(cel); #endregion passStationCount = 0; passTime = 0; } if (paths.Count == 0) { row++; #region 正常路线 rowDef = new TableRow(); rowDef.Height = Unit.Pixel(25); this.SetRow(rowDef, row); this.tbData.Rows.Add(rowDef); //0 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("subway.png", 15, 14); cel.Controls.Add(img); rowDef.Cells.Add(cel); //1 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; txt = new Literal(); txt.Text = passTime.ToString() + "分"; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //2 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("A" + tmpPriv.PathID + ".png", 6, 25); cel.Controls.Add(img); rowDef.Cells.Add(cel); //3 column cel = new TableCell(); txt = new Literal(); txt.Text = "【" + priv.PathName + "】 " + priv.StaName + "(全程)方向(" + passStationCount.ToString() + ")"; ; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //4 column rowDef.Cells.Add(new TableCell()); //5 column rowDef.Cells.Add(new TableCell()); #endregion } } //输出结束站点 row++; #region rowDef = new TableRow(); rowDef.Height = Unit.Pixel(25); this.SetRow(rowDef, row); this.tbData.Rows.Add(rowDef); //0 column rowDef.Cells.Add(new TableCell()); //1 column rowDef.Cells.Add(new TableCell()); //2 column cel = new TableCell(); cel.HorizontalAlign = HorizontalAlign.Center; img = this.GetImage("station.png", 14, 15); cel.Controls.Add(img); rowDef.Cells.Add(cel); //3 column cel = new TableCell(); txt = new Literal(); txt.Text = "【" + priv.PathName + "】 " + priv.StaName; cel.Controls.Add(txt); rowDef.Cells.Add(cel); //4 column rowDef.Cells.Add(new TableCell()); //5 column cel = this.GetOperateColumn(ret.passedNodeIDs, priv.ID); cel.HorizontalAlign = HorizontalAlign.Center; rowDef.Cells.Add(cel); #endregion }
/// <summary> /// 从PlanCourse表中取出目标及诶单的PassedPath,这个PassedPath即是规划结果 /// </summary> /// <param name="planCourse">迪克斯特拉(Dikastra)算法中,一个顶点到所有其他顶点的最短路径</param> /// <param name="destID">目标车站ID</param> /// <returns>到达目的站点的路线</returns> private RoutePlanResult GetResult(PlanCourse planCourse, string destID) { PassedPath pPath = planCourse[destID]; if (pPath.Weight == int.MaxValue) { RoutePlanResult result1 = new RoutePlanResult(null, int.MaxValue); return result1; } string[] passedNodeIDs = new string[pPath.PassedIDList.Count + 1]; for (int i = 0; i < passedNodeIDs.Length - 1; i++) { passedNodeIDs[i] = pPath.PassedIDList[i].ToString(); } passedNodeIDs[passedNodeIDs.Length - 1] = pPath.CurNodeID; RoutePlanResult result = new RoutePlanResult(passedNodeIDs, pPath.Weight); return result; }
private static void Reroute(Route r, IStation closest, IStation destination) { Sim target = r.Follower.Target as Sim; Vector3 currentStartPoint = r.GetCurrentStartPoint(); float distanceRemaining = r.GetDistanceRemaining(); Route route = target.CreateRoute(); route.SetOption(Route.RouteOption.EnableSubwayPlanning, false); route.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false); route.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar)); route.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller)); route.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller)); route.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller)); Slot routeEnterEndSlot = closest.RouteEnterEndSlot; if (routeEnterEndSlot != Slot.None) { GameObject routingSlotEnterFootprint = closest.RoutingSlotEnterFootprint; if (routingSlotEnterFootprint != null) { route.AddObjectToIgnoreForRoute(routingSlotEnterFootprint.ObjectId); } if (route.PlanToSlot(closest, routeEnterEndSlot).Succeeded()) { Slot routeExitBeginSlot = destination.RouteExitBeginSlot; Vector3 slotPosition = destination.GetSlotPosition(routeExitBeginSlot); GameObject routingSlotExitFootprint = destination.RoutingSlotExitFootprint; if (routingSlotExitFootprint != null) { r.AddObjectToIgnoreForRoute(routingSlotExitFootprint.ObjectId); } r.SetOption(Route.RouteOption.EnableSubwayPlanning, false); r.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false); if (!r.ReplanFromPoint(slotPosition).Succeeded()) { r.ReplanFromPoint(currentStartPoint); } else if ((route.GetDistanceRemaining() + r.GetDistanceRemaining()) < (distanceRemaining + SimRoutingComponent.kDistanceMustSaveInOrderToUseSubway)) { if (closest is IHoverTrainStation) { r.ReplanAllowed = false; Route route2 = target.CreateRoute(); PathType elevatedTrainPath = PathType.ElevatedTrainPath; List <Vector3> list = new List <Vector3>(); list.Add(closest.GetSlotPosition(closest.RouteEnterEndSlot)); list.Add(destination.GetSlotPosition(destination.RouteExitBeginSlot)); if (list.Count > 0) { route2.InsertCustomPathAtIndex(0, list.ToArray(), false, true, elevatedTrainPath); route2.ReplanAllowed = false; RoutePlanResult planResult = route2.PlanResult; planResult.mType = RoutePlanResultType.Succeeded; route2.PlanResult = planResult; PathData pathData = route2.GetPathData(0); pathData.ObjectId = destination.ObjectId; pathData.PathType = PathType.ElevatedTrainPath; route2.SetPathData(ref pathData); r.InsertRouteSubPathsAtIndex(0, route2); } } r.InsertRouteSubPathsAtIndex(0x0, route); r.SetOption(Route.RouteOption.EnableSubwayPlanning, true); r.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, true); } else { r.ReplanFromPoint(currentStartPoint); } } } }
public override bool Run() { try { RoutePlanResult result = Actor.CreateRoute().PlanToSlot(Target, Target.UseableSlots(Actor, true, true)); if (!result.Succeeded()) { return(false); } mSlotIndex = FairyHouse.kSlotToIndex[(Slot)result.mDestSlotNameHash]; Target.SetRoutingSlotInUse(mSlotIndex); if (Actor.IsActiveSim) { PlumbBob.HidePlumbBob(); } StandardEntry(false); BeginCommodityUpdates(); mActorFairy = Actor.SimDescription.OccultManager.GetOccultType(OccultTypes.Fairy) as OccultFairy; mCurrentStateMachine = Actor.Posture.CurrentStateMachine; AddOneShotScriptEventHandler(0x66, OnShowActorEx); SetParameter("Slot", FairyHouse.kSlotToCompass[mSlotIndex]); if (mActorFairy != null) { mActorFairy.FairyTrueForm.SetPosition(Target.GetPositionOfSlot((Slot)result.mDestSlotNameHash)); mActorFairy.FairyTrueForm.SetForward(Target.GetForwardOfSlot((Slot)result.mDestSlotNameHash)); } if (mActorFairy != null) { mActorFairy.AttachTrueFairyFormToAnimation(mCurrentStateMachine); } AnimateSim("Fly Out"); AnimateSim("Exit"); EndCommodityUpdates(true); StandardExit(); if (Target.IsLightOn() && (Target.ActorsUsingMe.Count == 0x0)) { Target.TurnOffLight(); } FairyHouse.FairyHousePosture posture = Actor.Posture as FairyHouse.FairyHousePosture; if (posture != null) { posture.CancelPosture(Actor); } Actor.PopPosture(); Actor.BridgeOrigin = Actor.Posture.Idle(); PlumbBob.Reparent(); return(true); } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(Actor, Target, e); return(false); } }
protected void Button1_Click(object sender, EventArgs e) { string pointA = ddlPointA.SelectedItem.Text; string pointB = ddlPointB.SelectedItem.Text; if (pointA == pointB) { Response.Write("不能起始地为同一处!"); } else { //生成图 ArrayList nodeList = new ArrayList(); string sql = "select PointA from tblDistance2020 group by PointA"; SQLHelper sh1 = new SQLHelper(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); try { sh1.RunSQL(sql, ref ds); if (ds.Tables[0] != null) { dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { Node node = new Node(dr[0].ToString()); nodeList.Add(node); string sql2 = string.Format("select * from tblDistance2020 where PointA='{0}'", dr[0].ToString()); SQLHelper sh2 = new SQLHelper(); DataTable dt2 = new DataTable(); DataSet ds2 = new DataSet(); sh2.RunSQL(sql2, ref ds2); if (ds2.Tables[0] != null) { dt2 = ds2.Tables[0]; if (dt2.Rows.Count > 0) { foreach (DataRow dr2 in dt2.Rows) { node.EdgeList.Add(new Edge(dr2[1].ToString(), dr2[2].ToString(), double.Parse(dr2[3].ToString()))); } } } sh2.Close(); } } } } catch (Exception ex) { Response.Write(ex.Message); } finally { sh1.Close(); } RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; try { result = planner.Paln(nodeList, pointA, pointB); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write(pointB); Response.Write("</br>"); planner = null; } catch { Response.Write("两地不能到达!"); } } }