/* * Add a node to the tree as a child of the given node. */ public TreeNode<StateConfig> addNode(StateConfig state, TreeNode<StateConfig> parent) { TreeNode<StateConfig> newNode = new TreeNode<StateConfig>(parent, state); // Add the new configuration as a child of the closest node. parent.addChild(newNode); nodeList.Add(newNode); return newNode; }
public RRT(StateConfig initialConfiguration, Tuple<float,float>[] limits, float increment, float goalBias, float goalDistanceThreshold) { this.initialConfiguration = initialConfiguration; this.increment = increment; this.goalSet = false; this.goalBias = goalBias; this.goalDistanceThreshold = goalDistanceThreshold; this.limits = limits; }
/// <summary> /// StateConfig新增 /// </summary> /// <param name="setting"></param> public void Insert_StateConfig(StateConfig setting) { try { using (var Conn = new MySqlConnection(scsb.ConnectionString)) { string sql = "INSERT IGNORE INTO StateConfig (DeviceTypeEnum,StateNo,CharAddress,StateName,StateBitAddress,StateFalg,StateHigh,StateLow)" + " VALUES(@DeviceTypeEnum,@StateNo,@CharAddress,@StateName,@StateBitAddress,@StateFalg,@StateHigh,@StateLow) "; Conn.Execute(sql, setting); } } catch (Exception ex) { Log.Error(ex, "StateConfig新增" + "錯誤(ChungHsin)"); } }
public void Test_MemZ3_Forward_Eq3() { StateConfig stateConfig = new StateConfig(); stateConfig.Set_All_Off(); stateConfig.RAX = true; stateConfig.RBX = true; stateConfig.RCX = true; stateConfig.R8 = true; stateConfig.Mem = true; State state = this.CreateState(stateConfig); Context ctx = state.Ctx; Tools tools = state.Tools; using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set(Rn.RBX, 10); updateState.Set(Rn.RCX, 5); state.Update_Forward(updateState); } BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax + 2 * rbx + 10]", state.HeadKey, tools, ctx); { StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools); updateState.Set(Rn.RAX, state.Ctx.MkBVAdd(state.Create(Rn.RAX), state.Ctx.MkBV(0, 64))); state.Update_Forward(updateState); } BitVecExpr address2 = Tools.Calc_Effective_Address("qword ptr[rax + 4 * rcx + 10]", state.HeadKey, tools, ctx); BitVecExpr value1 = state.Create(Rn.R8B); int nBytes = (int)value1.SortSize >> 3; using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set_Mem(address1, value1); state.Update_Forward(updateState); } BitVecExpr value2 = state.Create_Mem(address2, nBytes); if (LogToDisplay) { Console.WriteLine("value1 = " + value1); Console.WriteLine("value2 = " + value2); Console.WriteLine(state); } AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(value1, value2)); }
/// <summary> /// ConfigurationWatcher Test /// </summary> [Test] public void ConfigurationWatcherTest() { //Assembly a = Assembly.GetExecutingAssembly(); //Uri uri = new System.Uri(a.CodeBase); //string binDirectory = Path.GetDirectoryName(uri.LocalPath); string fileName = "test.config"; FileInfo fi = new FileInfo(fileName); if (!fi.Exists) { using (FileStream fs = fi.Create()); } // Configure a watcher ConfigureHandler configureDelegate = new ConfigureHandler(Configure); ConfigWatcherHandler.ClearFilesMonitored(); CustomUriBuilder builder = new CustomUriBuilder(fileName, AppDomain.CurrentDomain.BaseDirectory); IResource resource = new FileResource(builder.Uri); ConfigWatcherHandler.AddFileToWatch(resource.FileInfo); TimerCallback callBakDelegate = new TimerCallback(ConfigWatcherTest.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = fileName; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); resource.FileInfo.LastWriteTime = DateTime.Now; resource.FileInfo.Refresh(); // Let's give a small bit of time for the change to propagate. // The ConfigWatcherHandler class has a timer which // waits for 500 Millis before delivering // the event notification. System.Threading.Thread.Sleep(600); Assert.IsTrue(_hasChanged); }
/// <summary> /// Configure and monitor the configuration file for modifications /// and automatically reconfigure SqlMap. /// </summary> /// <param name="resource"> /// A FileInfo to your config file. /// </param> ///<param name="configureDelegate"> /// Delegate called when the file has changed, to rebuild the dal. /// </param> /// <returns>An SqlMap</returns> public void ConfigureAndWatch(FileInfo resource, ConfigureHandler configureDelegate) { XmlDocument document = Resources.GetFileInfoAsXmlDocument(resource); ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(resource); BuildDaoManagers(document, true); TimerCallback callBakDelegate = new TimerCallback(DomDaoManagerBuilder.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = resource.FullName; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); }
public void Test_MemZ3_Forward_Eq4() { StateConfig stateConfig = new StateConfig(); stateConfig.Set_All_Off(); stateConfig.RAX = true; stateConfig.RBX = true; stateConfig.RCX = true; stateConfig.RDX = true; stateConfig.Mem = true; State state = this.CreateState(stateConfig); Context ctx = state.Ctx; Tools tools = state.Tools; using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set(Rn.RAX, state.Create(Rn.RBX)); state.Update_Forward(updateState); } BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax]", state.HeadKey, tools, ctx); BitVecExpr address2 = Tools.Calc_Effective_Address("qword ptr[rbx]", state.HeadKey, tools, ctx); using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set_Mem(address1, state.Create(Rn.RCX)); state.Update_Forward(updateState); } using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set_Mem(address2, state.Create(Rn.RDX)); state.Update_Forward(updateState); } BitVecExpr value1 = state.Create_Mem(address1, 1); BitVecExpr value2 = state.Create_Mem(address2, 1); if (LogToDisplay) { Console.WriteLine("value1 = " + value1); Console.WriteLine("value2 = " + value2); Console.WriteLine(state); } AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(value1, value2)); }
public void Test_MemZ3_Forward_SetGet1() { StateConfig stateConfig = new StateConfig(); stateConfig.Set_All_Off(); stateConfig.RAX = true; stateConfig.R8 = true; stateConfig.R9 = true; stateConfig.Mem = true; State state = this.CreateState(stateConfig); Context ctx = state.Ctx; Tools tools = state.Tools; BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax]", state.HeadKey, tools, ctx); BitVecExpr value1a = state.Create(Rn.R8); BitVecExpr value2a = state.Create(Rn.R9); using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set_Mem(address1, value1a); state.Update_Forward(updateState); } BitVecExpr value1b = state.Create_Mem(address1, 8); using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools)) { updateState.Set_Mem(address1, value2a); state.Update_Forward(updateState); } BitVecExpr value2b = state.Create_Mem(address1, 8); if (LogToDisplay) { Console.WriteLine("value1a = " + value1a); Console.WriteLine("value1b = " + value1b); Console.WriteLine("value2a = " + value2a); Console.WriteLine("value2b = " + value2b); Console.WriteLine(state); } Assert.AreEqual(Tv.ONE, state.EqualValues(value1a, value1b)); Assert.AreEqual(Tv.ONE, state.EqualValues(value2a, value2b)); }
public TreeNode<StateConfig> findClosest(StateConfig config, SearchMethod search) { TreeNode<StateConfig> closestNode = nodeList[0]; float closestDistance = closestNode.content.computeDistanceEuclidean(config); float thisDistance = -1; TreeNode<StateConfig> currentNode = null; for (int i = 0; i < nodeList.Count; i++) { currentNode = nodeList[i]; if ((thisDistance = currentNode.content.computeDistanceEuclidean(config)) < closestDistance){ closestNode = currentNode; closestDistance = thisDistance; } } // if (search == SearchMethod.BFS){ // closestNode = findClosestBFS(config); // } else { // closestNode = findClosestDFS(config); // } return closestNode; }
public async Task <StateConfig> SaveStateAsync(StateConfig model) { State dbState = null; if (!model.StateId.HasValue) { dbState = new State { Name = model.Name }; await context.State.AddAsync(dbState); } else { dbState = await context.State.FirstOrDefaultAsync(s => s.StateId == model.StateId.Value); if (dbState == null) { throw new ApplicationException($"State with id {model.StateId.ToString()} was not found."); } dbState.Name = model.Name; context.State.Update(dbState); } try { await context.SaveChangesAsync(); } catch (Exception) { //logger.LogError(new EventId(5001), ex, string.Empty); throw; } return(await GetStateAsync(dbState.StateId)); }
/// <summary> /// StateConfig更新 /// </summary> /// <param name="setting"></param> public void Update_StateConfig(StateConfig setting) { try { using (var Conn = new MySqlConnection(scsb.ConnectionString)) { string sql = "UPDATE StateConfig SET " + "StateName = @StateName," + "CharAddress = @CharAddress," + "StateBitAddress = @StateBitAddress," + "StateFlag = @StateFlag," + "StateHigh = @StateHigh," + "StateLow = @StateLow" + " WHERE StateNo = @StateNo AND DeviceTypeEnum = @DeviceTypeEnum"; Conn.Execute(sql, setting); } } catch (Exception ex) { Log.Error(ex, "StateConfig更新" + "錯誤(ChungHsin)"); } }
public new ISqlMapper ConfigureAndWatch(string resource, ConfigureHandler configureDelegate) { XmlDocument document; if (resource.StartsWith("file://")) { document = Resources.GetUrlAsXmlDocument(resource.Remove(0, 7)); } else { document = Resources.GetResourceAsXmlDocument(resource); } ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(Resources.GetFileInfo(resource)); TimerCallback onWhatchedFileChange = new TimerCallback(DomSqlMapBuilder.OnConfigFileChange); StateConfig state = default(StateConfig); state.FileName = resource; state.ConfigureHandler = configureDelegate; ISqlMapper result = this.Build(document, true); new ConfigWatcherHandler(onWhatchedFileChange, state); return(result); }
public void ConfigurationWatcherTest() { Assembly a = Assembly.GetExecutingAssembly(); Uri uri = new System.Uri(a.Location); string binDirectory = Path.GetDirectoryName(uri.LocalPath); string fileName = "test.config"; // Configure a watcher ConfigureHandler configureDelegate = new ConfigureHandler(Configure); ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(Resources.GetFileInfo(fileName)); TimerCallback callBakDelegate = new TimerCallback(ConfigWatcherTest.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = fileName; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); FileInfo fi = Resources.GetFileInfo(fileName); fi.LastWriteTime = DateTime.Now; fi.Refresh(); // Let's give a small bit of time for the change to propagate. // The ConfigWatcherHandler class has a timer which // waits for 500 Millis before delivering // the event notification. System.Threading.Thread.Sleep(600); Assert.IsTrue(_hasChanged); }
public static StateConfig AddEvent(this StateConfig self, IncomingEventConfig e) { self.Events.Add(e.Name, e); return(self); }
public AssetsTreeView(TreeViewState treeViewState, MultiColumnHeader multiColumnHeader, ModuleConfig moduleConfig, StateConfig stateConfig) : base(treeViewState, multiColumnHeader) { this.moduleConfig = moduleConfig; this.stateConfig = stateConfig; #region TreeView设置 baseIndent = 0; cellMargin = 2; columnIndexForTreeFoldouts = 1; //depthIndentWidth (get only) extraSpaceBeforeIconAndLabel = 0; //foldoutWidth (get only) //hasSearch (get only) //isDragging (get only) //isInitialized (get only) //base.multiColumnHeader //rootItem (get only) rowHeight = 20; customFoldoutYOffset = (rowHeight - EditorGUIUtility.singleLineHeight) * 0.5f; //searchString showAlternatingRowBackgrounds = true; showBorder = true; //showingHorizontalScrollBar (get only) //showingVerticalScrollBar (get only) //state (get only) //totalHeight (get only) //treeViewControlID //treeViewRect #endregion #region MultiColumnHeader设置 base.multiColumnHeader.canSort = false; //base.multiColumnHeader.height = 25; base.multiColumnHeader.sortedColumnIndex = -1; //base.multiColumnHeader.sortingChanged += OnSortingChanged; #endregion emptyTexture = new Texture2D(1, 1, TextureFormat.RGBA32, false) { wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Point, anisoLevel = 1, mipMapBias = 0, }; emptyTexture.SetPixel(0, 0, new Color(0, 0, 0, 0)); emptyTexture.Apply(); multiColumnHeader.ResizeToFit(); Reload(); }
private void findPathToGoal() { // Debug.Log("---------------- generating random path -----------------"); StateConfig start = new StateConfig(new float[]{robot.transform.position.x, robot.transform.position.z}); StateConfig end = new StateConfig(new float[]{goal.first, goal.second}); NavigationPath path = null; path = prm.findShortestPath(start,end); if (path == null) { //GUI TEXT Debug.Log("Path not found!"); return; } // Debug.Log("Free path between start and goal? " + grid.obstacleFreeStraightPath(st.getPosition(), en.getPosition())); path.drawPath(0,"RobotCamera"); //Debug.Log("---------------- trimming path -----------------"); pathToGoal = path.trimPath(grid); pathToGoal.drawPath(1,"RobotCamera"); }
public void generatePRMGraph(int numNodes) { float x = 0; float y = 0; int placed = 0; while (placed < numNodes){ x = UnityEngine.Random.Range(-bounds.x, bounds.x); y = UnityEngine.Random.Range(-bounds.z, bounds.z); if (occupancy.isOccupied(x,y)) continue; float[] arr = {x,y}; StateConfig nw = new StateConfig(arr); graph.addNode(new GraphNode<StateConfig>(nw,5)); placed++; } if (method == ConnectionMethod.KNEAREST) connectNodesKNN(neighbours); if (method == ConnectionMethod.RADIUS) connectNodesRadius(radius); if (method == ConnectionMethod.NEIGHBOURHOOD) connectNodesNeighbourhood(neighbours, radius); search.graph = graph; }
public NavigationPath findShortestPath(StateConfig start, StateConfig goal) { GraphNode<StateConfig> startNode = new GraphNode<StateConfig>(start,5); GraphNode<StateConfig> goalNode = new GraphNode<StateConfig>(goal,5); connectNode(startNode); connectNode(goalNode); return search.findShortestPath(startNode, goalNode); }
public abstract bool ShouldRunState(AgentController owner, out StateConfig config);
/// <summary> /// state : /// STATE key comment? /// (ON (ENTER STATE | EXIT STATE | ENTER AND EXIT STATE) execute)* /// on_event_statement* /// ; /// </summary> /// <param name="context"></param> /// <returns></returns> public override object VisitState([NotNull] WorkflowParser.StateContext context) { string comment = string.Empty; var c = context.comment(); if (c != null) { comment = (string)Visit(c); } StateConfig state = new StateConfig() { Name = (string)VisitKey(context.key()), Label = comment, }; var executes = context.execute(); if (executes != null) { foreach (var execute in executes) { var e = ((bool, bool, ResultRuleConfig))VisitExecute(execute); if (e.Item1) { state.IncomingRules.Add(e.Item3); } if (e.Item2) { state.OutcomingRules.Add(e.Item3); } } } var on_event_statements = context.on_event_statement(); if (on_event_statements != null) { foreach (var on_event_statement in on_event_statements) { var e = ((IncomingEventConfig, List <(string, ResultRuleConfig)>))VisitOn_event_statement(on_event_statement); if (state.Events.TryGetValue(e.Item1.Name, out IncomingEventConfig ic)) { throw new Exceptions.DuplicatedArgumentNameMethodReferenceException($"event name {e.Item1.Name} in {state.Name}"); } state.Events.Add(e.Item1.Name, e.Item1); foreach (var item in e.Item2) { switch (item.Item1) { case "in": state.IncomingRules.Add(item.Item2); break; case "out": state.OutcomingRules.Add(item.Item2); break; default: break; } } } } return(state); }
public DefendState(StateConfig config) : base(config) { }
public override bool ShouldRunState(AgentController owner, out StateConfig config) { config = null; return(false); }
public SpecialistState(StateConfig config) : base(config) { }
/* * Finds the node in the graph which has contents closest to * the data item provided. */ public GraphNode<StateConfig> findClosest(StateConfig data) { GraphNode<StateConfig> closestNode = nodes[0]; float closestDistance = closestNode.content.computeDistanceEuclidean(data); float thisDistance = -1; GraphNode<StateConfig> currentNode = null; for (int i = 0; i < nodes.Count; i++) { currentNode = nodes[i]; if ((thisDistance = currentNode.content.computeDistanceEuclidean(data)) < closestDistance){ closestNode = currentNode; closestDistance = thisDistance; } } return closestNode; }
private TreeNode<StateConfig> findClosestBFS(StateConfig start) { TreeNode<StateConfig> closestNode = null; float closestDistance = float.MaxValue; Queue q = new Queue(); q.Enqueue(root); while(q.Count != 0){ Debug.Log("expanded front"); Debug.Log("Queue size: " + q.Count); TreeNode<StateConfig> front = (TreeNode<StateConfig>)q.Dequeue(); float thisDistance = front.content.computeDistanceEuclidean(start); if (thisDistance < closestDistance){ closestDistance = thisDistance; closestNode = front; } foreach (var child in front.children) { q.Enqueue(child); } } return closestNode; }
public static WorkflowConfig AddState(this WorkflowConfig self, StateConfig state) { self.States.Add(state.Name, state); return(self); }
/// <summary> /// Called when the configuration has been updated. /// </summary> /// <param name="obj">The state config.</param> public static void OnConfigFileChange(object obj) { StateConfig state = (StateConfig)obj; state.ConfigureHandler(null); }
public Tree(StateConfig root) { this.root = new TreeNode<StateConfig>(null, root); nodeList = new List<TreeNode<StateConfig>>(); nodeList.Add(this.root); }
private TreeNode<StateConfig> findClosestDFS(StateConfig start) { TreeNode<StateConfig> closestNode = null; float closestDistance = float.MaxValue; Stack s = new Stack(); s.Push(root); while(s.Count != 0){ TreeNode<StateConfig> front = (TreeNode<StateConfig>)s.Pop(); float thisDistance = front.content.computeDistanceEuclidean(start); if (thisDistance < closestDistance){ closestDistance = thisDistance; closestNode = front; } foreach (var child in front.children) { s.Push(child); } } return closestNode; }