//TODO: public int MaxDepth = 10; public Queue <GAction> Plan(GAgent agent, HashSet <GAction> availableActions, Dictionary <string, object> worldState, Dictionary <string, object> goalState) { foreach (GAction a in availableActions) { a.ResetVariables(); } // check what actions can run using their checkProceduralPrecondition HashSet <GAction> usableActions = new HashSet <GAction>(); foreach (GAction a in availableActions) { if (a.CheckProceduralPrecondition(agent)) { usableActions.Add(a); } } List <GNode> leaves = new List <GNode>(); Debug.Log("Started planing"); GNode start = new GNode(null, 0, worldState, null); bool success = BuildGraph(start, leaves, usableActions, goalState); if (!success) { Debug.Log("No plan found!"); return(null); } GNode cheapest = null; foreach (GNode leaf in leaves) { if (cheapest == null) { cheapest = leaf; } else { if (leaf.runningCost < cheapest.runningCost) { cheapest = leaf; } } } List <GAction> result = new List <GAction>(); GNode n = cheapest; while (n != null) //puts the cheapest branch of leaves in order in result { if (n.action != null) { result.Insert(0, n.action); } n = n.parent; } //is this necesary? maybe implement this loop in previous loop. Queue <GAction> queue = new Queue <GAction>(); foreach (GAction a in result) { queue.Enqueue(a); } return(queue); }
//public bool visit = false; public GEdge(GNode first, GNode second) { this.first = first; this.second = second; }
public JsonResult GetList(string EngineeringInfoID) { var engineeringInfo = entities.Set <S_I_Engineering>().Find(EngineeringInfoID); if (engineeringInfo == null) { throw new BusinessException("无法找到对应工程数据"); } if (engineeringInfo.Mode == null) { throw new BusinessException("未能找到该工程的模式定义"); } string defineID = engineeringInfo.Mode.ToDoListDefine; List <Lane> lanes = new List <Lane>(); if (!string.IsNullOrEmpty(defineID)) { var dbContext = FormulaHelper.GetEntities <InfrastructureEntities>(); var define = dbContext.Set <S_T_ToDoListDefine>().Find(defineID); if (define == null) { throw new BusinessException("无法找到对应代办事项定义"); } var defineNodes = define.S_T_ToDoListDefineNode; var categories = defineNodes.Where(a => a.Type == "Category"); #region 读取数据 DateTime?minCreateDate = null; DateTime?maxCreateDate = null; foreach (var cat in categories) { Lane lane = new Lane(); var taskList = defineNodes.Where(a => a.ParentID == cat.ID); List <GNode> nodes = new List <GNode>(); foreach (var task in taskList) { GNode node = new GNode(); var toDo = entities.Set <S_T_ToDoList>().FirstOrDefault(a => a.EngineeringInfoID == EngineeringInfoID && a.DefineNodeID == task.ID); node.BotTitle = task.Name; if (toDo != null) { node.CreateDate = toDo.CreateDate; if (toDo.FinishTime != null) { node.State = "Excute"; node.ExcuteDate = toDo.FinishTime; } else { node.State = "Create"; } minCreateDate = MinDate(minCreateDate, toDo.CreateDate.Date); maxCreateDate = MaxDate(maxCreateDate, toDo.CreateDate.Date); } node.SortIndex = task.SortIndex; node.Draw = true; nodes.Add(node); } lane.Title = cat.Name; lane.Nodes = nodes; lanes.Add(lane); } #endregion #region 数据处理 //按时间分割排 if (minCreateDate != null && maxCreateDate != null) { DateTime index = minCreateDate.Value; while (index <= maxCreateDate) { //遍历所有泳道,对节点进行重拍 foreach (var lan in lanes) { //该时间节点上的任务节点的draw为true var nodes = lan.Nodes.Where(a => a.CreateDate != null && a.CreateDate.Date == index).ToList(); //如果没有,必须加一个绘制用节点 if (nodes.Count == 0) { GNode node = new GNode(); node.CreateDate = index; node.Draw = false; lan.Nodes.Add(node); } //移除多余节点,保留一个,并将描述合并到一个节点 else { var singNode = nodes[0]; nodes.Remove(singNode); lan.Nodes.RemoveAll(a => nodes.Contains(a)); if (nodes.Count > 0) { singNode.MultiBotTitle = singNode.BotTitle; singNode.BotTitle += "..."; } foreach (var node in nodes) { singNode.MultiBotTitle += "/" + node.BotTitle; } singNode.Draw = true; } } index = index.AddDays(1); } } lanes.ForEach(a => a.Nodes = a.Nodes.OrderBy(b => b.CreateDate).ThenBy(c => c.SortIndex).ToList());//先由实例CreateDate排序,再由模板的SortIndex排序 #endregion } return(Json(new { Lanes = lanes, MaxNodeCount = lanes.Max(a => a.Nodes.Count), InstanceNodeCount = lanes.Max(a => a.Nodes.Count(b => b.CreateDate != DateTime.MaxValue)) })); }
public Point GetXYByName(string name) //получить координаты(структура точка) узла по имени { GNode n = Nodes[GetNodeIndexByName(name)]; return(new Point(n.x, n.y)); }
public Point GetXYByIndex(int index) //получить координаты(структура точка) узла по индексу { GNode n = Nodes[index]; return(new Point(n.x, n.y)); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(DefaultErrorHandler); Console.WriteLine("\nAlchemi [.NET Grid Computing Framework]"); Console.WriteLine("http://www.alchemi.net\n"); Console.WriteLine("Job Submitter v{0}", Utils.AssemblyVersion); IManager manager; SecurityCredentials sc; if (args.Length < 4) { Usage(); return; } try { manager = (IManager)GNode.GetRemoteRef(new RemoteEndPoint(args[0], int.Parse(args[1]), RemotingMechanism.TcpBinary)); manager.PingManager(); sc = new SecurityCredentials(args[2], args[3]); manager.AuthenticateUser(sc); Console.Write("Connected to Manager at {0}:{1}\n", args[0], args[1]); } catch (Exception e) { Error("Could not connect to Manager", e); return; } Aliases aliases = Aliases.FromFile(Path.Combine(System.Windows.Forms.Application.StartupPath, "aliases.dat")); string[] cmd; bool interactive; if (args.Length > 4) { cmd = new string[args.Length - 4]; for (int i = 0; i < args.Length - 4; i++) { cmd[i] = args[i + 4]; } interactive = false; } else { cmd = new string[] { "" }; interactive = true; } while (true) { if (interactive) { Console.Write("\n> "); string line = Console.ReadLine(); cmd = line.Split(); cmd[0] = cmd[0].ToLower(); } try { string appId; switch (cmd[0]) { case "st": case "submittask": // taskXmlFile string task = EmbedFiles(Utils.ReadStringFromFile(cmd[1])); appId = CrossPlatformHelper.CreateTask(manager, sc, task); string newAlias = aliases.NewAlias(appId); try { WriteLine("Task submitted (alias = {1}).", appId, newAlias); } catch { } break; case "gfj": case "getfinishedjobs": // alias, (directory, default=".") appId = (string)aliases.Table[cmd[1]]; string taskDir = cmd.Length > 2 ? cmd[2] : "."; string taskXml = CrossPlatformHelper.GetFinishedJobs(manager, sc, appId); XmlDocument fin = new XmlDocument(); fin.LoadXml(taskXml); WriteLine("Got {0} job(s).", fin.SelectNodes("task/job").Count); Console.WriteLine("Job XML: \n" + taskXml); foreach (XmlNode outputFileNode in fin.SelectNodes("task/job/output/embedded_file")) { //string jobDir = string.Format("{0}\\job_{1}", taskDir, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value); string jobDir = taskDir; if (!Directory.Exists(jobDir)) { Directory.CreateDirectory(jobDir); } //if (outputFileNode.InnerText != "") //{ string filePath = string.Format("{0}\\{1}", jobDir, outputFileNode.Attributes["name"].Value); Utils.WriteBase64EncodedToFile( filePath, outputFileNode.InnerText ); WriteLine("Wrote file {0} for job {1}.", filePath, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value); // } } break; // TODO: (allow option to specify alias) case "ct": case "createtask": // no arguments appId = manager.Owner_CreateApplication(sc); WriteLine(appId); WriteLine("Task created (alias = {1}).", appId, aliases.NewAlias(appId)); break; case "aj": case "addjob": // alias, jobXml, jobId, (priority, default=0) appId = (string)aliases.Table[cmd[1]]; int priority = 0; if (cmd.Length > 4) { priority = int.Parse(cmd[4]); } CrossPlatformHelper.AddJob(manager, sc, appId, int.Parse(cmd[3]), priority, EmbedFiles(Utils.ReadStringFromFile(cmd[2]))); WriteLine("Job added."); break; /* * case "listapps": // no arguments * DataTable apps = manager.Owner_GetLiveApplicationList(null).Tables[0]; * apps.Columns.Add("alias", typeof(string)); * apps.Columns.Add("state_disp", typeof(string)); * foreach (DataRow app in apps.Rows) * { * string alias = aliases.GetAlias(app["application_id"].ToString()); * if (alias == "") * { * alias = aliases.NewAlias(app["application_id"].ToString()); * } * app["alias"] = alias; * app["state_disp"] = Enum.Parse(typeof(ApplicationState), app["state"].ToString()).ToString(); * } * Console.WriteLine(ConsoleFormatter.FormatDataTable( * apps, * new string[] {"alias", "state_disp", "time_created"}, * new string[] {"alias", "state", "time_created"} * )); * break; * * case "listthreads": // alias * appId = (string) aliases.Table[cmd[1]]; * DataTable threads = manager.Owner_GetThreadList(null, appId).Tables[0]; * * threads.Columns.Add("state_disp", typeof(string)); * foreach (DataRow thread in threads.Rows) * { * thread["state_disp"] = Enum.Parse(typeof(ThreadState), thread["state"].ToString()); * } * * Console.WriteLine(ConsoleFormatter.FormatDataTable( * threads, * new string[] {"thread_id", "state_disp", "time_started", "time_finished"}, * new string[] {"thread_id", "state", "time_started", "time_finished"} * )); * break; * * case "getthreadstate": // alias, threadId * appId = (string) aliases.Table[cmd[1]]; * ThreadState state = manager.Owner_GetThreadState(null, new ThreadIdentifier(appId, int.Parse(cmd[2]))); * WriteLine("State = {0}.", state); * break; * * case "abortthread": // alias, threadId * appId = (string) aliases.Table[cmd[1]]; * manager.Owner_AbortThread(null, new ThreadIdentifier(appId, int.Parse(cmd[2]))); * WriteLine("Thread aborted."); * break; * * case "stoptask": // alias * appId = (string) aliases.Table[cmd[1]]; * manager.Owner_StopApplication(null, appId); * WriteLine("Task stopped."); * break; * */ case "h": case "help": case "?": if (cmd.Length == 2) { Usage(cmd[1]); } else { Usage(); } break; case "quit": case "q": case "exit": case "x": return; default: Error("Unknown command '{0}'", cmd[0]); break; } } catch (Exception e) { Error("Incorrect syntax or parameter (" + e.Message.ToString() + ")"); } if (!interactive) { return; } } }
public void CleanSelected() { selected = null; }
public void addNodes(T id) { GNode n = new GNode(id); graphNodes.Add(id, n); }
public bool CanFinish(int numCourses, int[][] prerequisites) { if (prerequisites.Length == 0) { return(true); // no cycle could be formed in empty graph. } // course -> list of next courses Dictionary <int, GNode> graph = new Dictionary <int, GNode>(); // build the graph first foreach (int[] relation in prerequisites) { // relation[1] -> relation[0] GNode prevCourse = this.GetCreateGNode(graph, relation[1]); GNode nextCourse = this.GetCreateGNode(graph, relation[0]); prevCourse.outNodes.Add(relation[0]); nextCourse.inDegrees += 1; } // We start from courses that have no prerequisites. int totalDeps = prerequisites.Length; Stack <int> nodepCourses = new Stack <int>(); foreach (var entry in graph) { GNode node = entry.Value; if (node.inDegrees == 0) { nodepCourses.Push(entry.Key); } } int removedEdges = 0; while (nodepCourses.Count > 0) { int course = nodepCourses.Pop(); foreach (int nextCourse in graph[course].outNodes) { GNode childNode = graph[nextCourse]; childNode.inDegrees -= 1; removedEdges += 1; if (childNode.inDegrees == 0) { nodepCourses.Push(nextCourse); } } } if (removedEdges != totalDeps) { // if there are still some edges left, then there exist some cycles // Due to the dead-lock (dependencies), we cannot remove the cyclic edges return(false); } else { return(true); } }
public Point GetXYByName(string name) { GNode n = Nodes[GetNodeIndexByName(name)]; return(new Point(n.x, n.y)); }
public Point GetXYByIndex(int index) { GNode n = Nodes[index]; return(new Point(n.x, n.y)); }
public ActivityPickup(Task t, GNode node) : base(t, "Pickup " + node.Name) { this.node = node; }
private bool NodeInGridSizeBounds(out GNode n, int i, int gridWidth, GNode[] nodes) { n = (i < 0 || i >= nodes.Length) ? null : nodes[i]; return(n != null); }
private double estimate(GNode n) { return(n.manhattanDistance); }
public NodeVariableProperties(GNodeVariable p_var) { m_var = p_var; }
public Queue <GAction> plan(List <GAction> actions, Dictionary <string, int> goal, WorldStates states) { List <GAction> usableActions = new List <GAction>(); foreach (GAction a in actions) { if (a.isAcheivable()) { usableActions.Add(a); } } List <GNode> leaves = new List <GNode>(); GNode start = new GNode(null, 0, GWorld.Instance.GetWorld().GetStates(), null); bool success = BuildGraph(start, leaves, usableActions, goal); if (!success) { Debug.Log("No Plan"); return(null); } GNode cheapest = null; foreach (GNode leaf in leaves) { if (cheapest == null) { cheapest = leaf; } else { if (leaf.cost < cheapest.cost) { cheapest = leaf; } } } List <GAction> result = new List <GAction>(); GNode n = cheapest; while (n != null) { if (n.action != null) { result.Insert(0, n.action); } n = n.parent; } Queue <GAction> queue = new Queue <GAction>(); foreach (GAction a in result) { queue.Enqueue(a); } //---------------------------------------- Debug.Log("Plan Found: "); // foreach (GAction a in queue) // { // Debug.Log("Q: " + a.actionName); // } // //---------------------------------------- return(queue); }