public void showProperties(Netron.GraphLib.UI.GraphControl GC, grammarRule rule1, object[] props) { graphControl = GC; rule = rule1; if (graphControl.Name == "graphControlLHS") { graph = rule.L; } else { graph = rule.R; } rule.updateFromGraphControl(graphControl); try { this.graphRulePropsTab.Text = "Rule Properties"; if (rule.Bag == null) { rule.initPropertiesBag(); } this.graphRuleProps.SelectedObject = rule.Bag; } catch (Exception exc) { MessageBox.Show("The properties of the rule has thrown an exception and cannot be displayed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SearchIO.output(exc.Message, 2); } showDisplayProperties(graphControl, (Netron.GraphLib.PropertyBag)props[0]); showRuleNodeArcProperties((Netron.GraphLib.PropertyBag)props[0], graph); }
protected static void SaveTable(string filename, List <partTableEntry> solids) { StreamWriter tableWriter = null; try { tableWriter = new StreamWriter(filename); var s = SerializeGraphToXml(solids); if (s != null) { tableWriter.Write(s); } } catch (FileNotFoundException fnfe) { SearchIO.output("***Error Writing to File***"); SearchIO.output(fnfe.ToString()); } finally { if (tableWriter != null) { tableWriter.Close(); } } }
public void runGUIOrRandomTest() { candidate cand = generateOneCandidate(); SearchIO.addAndShowGraphDisplay(cand.graph, "After Rule Application"); System.Threading.Thread.CurrentThread.Abort(); }
private static List <string> getPotentialAssemblies(string directory) { var potentialAssemblies = Directory.GetFiles(GlobalSettings.ExecDir, "*.dll", SearchOption.TopDirectoryOnly).ToList(); if (Directory.Exists(GlobalSettings.ExecDir + defaultPluginDir)) { potentialAssemblies.AddRange(Directory.GetFiles(GlobalSettings.ExecDir + defaultPluginDir, "*.dll", SearchOption.AllDirectories)); } if (Directory.Exists(directory)) { potentialAssemblies.AddRange(Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories)); } else { SearchIO.output("Plugin directory" + directory + " not found."); } potentialAssemblies.RemoveAll(fs => fs.Contains("/obj/")); potentialAssemblies.RemoveAll(fs => fs.Contains("GraphSynth.CustomControls.dll")); potentialAssemblies.RemoveAll(fs => fs.Contains("GraphSynth.BaseClasses.dll")); potentialAssemblies.RemoveAll(fs => fs.Contains("StarMath.dll")); potentialAssemblies.RemoveAll(fs => fs.Contains("OptimizationToolbox.dll")); return(potentialAssemblies); }
private void updateTimeDisplay() { var dispStr = ""; var dispTime = new TimeSpan(DateTime.Now.Ticks - startTime); SearchIO.setTimeInterval(searchThread.ManagedThreadId, dispTime); if (dispTime.Days > 0) { dispStr += dispTime.Days + ","; } if (dispTime.Hours > 0) { dispStr += dispTime.Hours.ToString().PadLeft(2, '0') + ":"; } if (dispTime.Minutes > 0) { dispStr += dispTime.Minutes.ToString().PadLeft(2, '0') + ":"; } if (dispTime.TotalMilliseconds > 1) { lblTimeDisplay.Content = dispStr + dispTime.Seconds.ToString().PadLeft(2, '0') + "." + dispTime.Milliseconds.ToString().PadRight(3, '0'); } else { lblTimeDisplay.Content = "DD,hh:mm:ss.sss"; } }
public static CanvasProperty DeSerializeFromXML(string xmlString) { try { /* to make it load old versions of the CanvasProperties from * 1/2009 to 9/2009, we replace Canvas with CanvasProperty */ xmlString = xmlString.Replace("<Canvas ", "<CanvasProperty "); xmlString = xmlString.Replace("</Canvas>", "</CanvasProperty>"); var context = new ParserContext(); context.XmlnsDictionary.Add("GraphSynth", "clr-namespace:GraphSynth.UI;assembly=GraphSynth"); var canvas = (CanvasProperty)MyXamlHelpers.Parse(xmlString, context); /***** Notice!: If you have crashed GS2.0 here, then * the try-catch failed. This happens due to a setting * in your Visual Studio environment. To fix this: * 1) Go to Debug->Exceptions. * 2) expand Common Language Runtime Exceptions * 3) Scroll Down to System.Windows.Markup.XamlParseException * 4) uncheck the box in the "Thrown" Column. */ /* any negative values in CanvasWidth are reset to zero s.t. there are not problems in * re-opening the canvas. */ canvas.CanvasWidth = new Thickness(Math.Max(0.0, canvas.CanvasWidth.Left), Math.Max(0.0, canvas.CanvasWidth.Top), Math.Max(0.0, canvas.CanvasWidth.Right), Math.Max(0.0, canvas.CanvasWidth.Bottom)); return(canvas); } catch { SearchIO.output("Failed to open Canvas data from file. " + "It is likely non-existent, or in an old format."); return(new CanvasProperty()); } }
/// <summary> /// Initializes a new instance of the <see cref="RecognizeChooseApply" /> class. /// </summary> /// <param name="host">The _seed.</param> /// <param name="rulesets">The _rulesets.</param> /// <param name="maxNumOfCalls">The _max num of calls.</param> /// <param name="display">if set to <c>true</c> [_display].</param> /// <param name="inParallel">The process should be invoked in parallel where possible.</param> protected RecognizeChooseApply(designGraph host, ruleSet[] rulesets, int[] maxNumOfCalls = null, Boolean display = false, Boolean inParallel = true) { SearchIO.output("initializing RCA generation:", 4); Rulesets = (ruleSet[])rulesets.Clone(); NumOfRuleSets = rulesets.GetLength(0); SearchIO.output("There are " + NumOfRuleSets + " rule sets.", 4); Host = new candidate(host, NumOfRuleSets); SearchIO.output("Host = " + host.name, 4); MaxNumOfCalls = new int[rulesets.GetLength(0)]; for (var i = 0; i < this.MaxNumOfCalls.GetLength(0); i++) { if (maxNumOfCalls == null) { this.MaxNumOfCalls[i] = -1; } else if (maxNumOfCalls.GetLength(0) <= i) { this.MaxNumOfCalls[i] = maxNumOfCalls[0]; } else { this.MaxNumOfCalls[i] = maxNumOfCalls[i]; } } Display = display; SearchIO.output("It is " + display + " that the SearchIO will be displayed.", 4); InParallel = inParallel; }
public TimeSpan getIntervalFromVerbosity() { /* this is a very subjective little function. Basically, we want to * update the searchProcessController more often for high verbosity * systems. The time it returns is in tenths-of-a-microsecond, and * so 10,000 corresponds to an update every millisecond and 10,000,000 * is a second. */ switch (SearchIO.getVerbosity(searchThread.ManagedThreadId)) { case 0: return(new TimeSpan(25000000)); case 1: return(new TimeSpan(10000000)); case 2: return(new TimeSpan(5000000)); case 3: return(new TimeSpan(1000000)); case 4: return(new TimeSpan(500000)); } return(new TimeSpan(500000)); }
public searchProcessController(SearchProcess sp, int processNum) { /* the following is common to all GS window types. */ InitializeComponent(); Owner = GSApp.main; //ShowInTaskbar = false; foreach (CommandBinding cb in GSApp.main.CommandBindings) { CommandBindings.Add(cb); } foreach (InputBinding ib in GSApp.main.InputBindings) { InputBindings.Add(ib); } /***************************************************/ try { InitializePriorityAndVerbosityComboBoxes(); searchThread = new Thread(sp.RunSearchProcess); searchThread.SetApartmentState(ApartmentState.STA); searchThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; //this.Text = "Search Process #" + processNum.ToString(); searchThread.Name = "S" + processNum + "> "; cmbPriority.SelectedIndex = 0; SearchIO.setVerbosity(searchThread.ManagedThreadId, GSApp.settings.DefaultVerbosity); cmbVerbosity.SelectedIndex = GSApp.settings.DefaultVerbosity; processTimer.Tick += updateSPCDisplay; processTimer.Interval = getIntervalFromVerbosity(); } catch (Exception exc) { ErrorLogger.Catch(exc); } }
private void btnAbort_Click(object sender, RoutedEventArgs e) { try { if (searchThread.ThreadState == ThreadState.Suspended) { searchThread.Resume(); } if ((searchThread.ThreadState == ThreadState.Running) || (searchThread.ThreadState == ThreadState.WaitSleepJoin) || (searchThread.ThreadState == ThreadState.AbortRequested) || (searchThread.ThreadState == ThreadState.StopRequested) || (searchThread.ThreadState == ThreadState.SuspendRequested)) { searchThread.Abort(); searchThread.Join(); } else { SearchIO.output("Cannot hard-stop thread because it is " + searchThread.ThreadState, 2); } } catch (Exception exc) { ErrorLogger.Catch(exc); } }
public void btnPlay_Click(object sender, RoutedEventArgs e) { try { switch (searchThread.ThreadState) { case ThreadState.Unstarted: searchThread.Start(); processTimer.Start(); startTime = DateTime.Now.Ticks; break; case ThreadState.WaitSleepJoin: case ThreadState.Suspended: case ThreadState.Running: searchThread.Resume(); processTimer.IsEnabled = true; startTime = DateTime.Now.Ticks - SearchIO.getTimeInterval(searchThread.ManagedThreadId).Ticks; break; default: SearchIO.output("Cannot (re-)start thread because it is " + searchThread.ThreadState, 2); break; } } catch (Exception exc) { ErrorLogger.Catch(exc); } }
public static void checkForRuleFile(ruleSet rs, List <string> ruleFiles, string str) { if (!str.EndsWith(".cs")) { str += ".cs"; } if (ruleFiles.Contains(str)) { SearchIO.output(rs.name + " already contains a reference to code file, " + str + "."); } else if (!File.Exists(rs.rulesDir + str)) { var result = MessageBox.Show("Source File " + rs.rulesDir + str + " not found. Would you like to create it?", "File not found.", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { createRulesSourceFile(rs.rulesDir + str); ruleFiles.Add(str); } } else { SearchIO.output("Code file, " + str + " found: Adding file reference to ruleset."); ruleFiles.Add(str); } }
public static Color GetColorFromString(String sColor) { int intColor; byte[] colorBytes; if (int.TryParse(sColor, out intColor)) { colorBytes = BitConverter.GetBytes(intColor); return(Color.FromArgb(colorBytes[3], colorBytes[2], colorBytes[1], colorBytes[0])); } if (int.TryParse(sColor.Replace("#", ""), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out intColor)) { colorBytes = BitConverter.GetBytes(intColor); return(Color.FromArgb(colorBytes[3], colorBytes[2], colorBytes[1], colorBytes[0])); } var propInfo = typeof(Colors).GetProperty(sColor); if (propInfo != null) { return((Color)propInfo.GetGetMethod().Invoke(null, null)); } SearchIO.output(sColor + " is not a member of the Colors enumeration.", 3); return(Colors.Transparent); }
public void OpenAndShow(string filename) { var openedItems = GSApp.settings.filer.Open(filename); if (openedItems == null) { return; } else if (openedItems[0] is ruleSet) { var rs = (ruleSet)openedItems[0]; addAndShowRuleSetWindow(rs, filename); } else if (openedItems[0] is candidate) { var tempString = ""; var c = (candidate)openedItems[0]; SearchIO.output("The candidate found in " + filename, 0); if (c.performanceParams.Count > 0) { tempString = "has the following performance parameters"; foreach (double a in c.performanceParams) { tempString += ": " + a; } SearchIO.output(tempString, 0); } if (c.age > 0) { SearchIO.output("The candidate has existed for " + c.age + " iterations.", 0); } SearchIO.output("Its generation ended in RuleSet #" + c.activeRuleSetIndex, 0); tempString = "Generation terminated with"; foreach (GenerationStatuses a in c.GenerationStatus) { tempString += ": " + a; } SearchIO.output(tempString, 0); c.graph.RepairGraphConnections(); ((WPFFiler)GSApp.settings.filer).RestoreDisplayShapes(null, c.graph.nodes, c.graph.arcs, c.graph.hyperarcs); //System.Windows.MessageBox.Show("Code for Candidate"); addAndShowGraphWindow(c.graph, filename); // graphWindow gW = new graphWindow(c.graph, filename); // windowsMgr.AddandShowWindow(gW); } else if (openedItems[0] is designGraph) { addAndShowGraphWindow(openedItems); } else if (openedItems[0] is grammarRule) { addAndShowRuleWindow(openedItems); } else { SearchIO.output("Nothing opened. No GraphSynth object found in " + filename); } }
private void processTimer_Tick(object sender, ElapsedEventArgs e) { if (!SearchIO.GetTerminateRequest(Thread.CurrentThread.Name)) { return; } choice = new[] { -2 }; Close(); }
private void cmbVerbosity_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { SearchIO.setVerbosity(searchThread.ManagedThreadId, cmbVerbosity.SelectedIndex); } catch (Exception exc) { ErrorLogger.Catch(exc); } }
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { if (e.ClickCount >= 2) { SearchIO.addAndShowGraphWindow(_opt.copy(), "Location for Option " + _opt.optionNumber + " from RuleSet " + _opt.ruleSetIndex + " Rule #" + _opt.ruleNumber + ": " + StrLocation); } base.OnPreviewMouseDown(e); }
public double calculate(double[] x) { double numberOfPasses = (x[0] - 5) * (x[0] - 5); /* optimal @ 5 */ double length = (x[1] - 25) / 25; /* optimal @ 50 */ double angle = (x[2] + 150) / 30; /* optimal @ -120*/ /* this is a made up function - basically the banana function again offset*/ var f = numberOfPasses + ((1 - length) * (1 - length) + 100.0 * (angle - length * length) * (angle - length * length)); SearchIO.output(f, 10); return(f); }
private void showDisplayProperties(Netron.GraphLib.UI.GraphControl GC, PropertyBag shapeProps) { try { this.displayProps.SelectedObject = shapeProps; } catch (Exception exc) { MessageBox.Show("The display properties cannot be displayed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SearchIO.output(exc.Message, 2); } }
private void stopButton_Click(object sender, EventArgs e) { if (searchThread.ThreadState != ThreadState.Suspended) { SearchIO.setTerminationRequest(searchThread.Name); SearchIO.output("A stop request has been sent to your search process.", 1); } else { SearchIO.output("Cannot stop thread because it is currently paused.", 2); } }
private void pauseButton_Click(object sender, EventArgs e) { if ((searchThread.ThreadState == ThreadState.Running) || (searchThread.ThreadState == ThreadState.WaitSleepJoin)) { searchThread.Suspend(); } else { SearchIO.output("Cannot pause thread because it is " + searchThread.ThreadState.ToString(), 2); } }
protected override void Run() { var display = (MessageBoxResult.Yes == MessageBox.Show("Would you like to see the graph " + "after each rule application?", "Display Interim Graphs", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No)); var userChoose = new UserChooseRCA(seedGraph, rulesets, settings, display); //userChoose.InParallel = false; // this is left here to help with debugging var cand = userChoose.GenerateOneCandidate(); SearchIO.addAndShowGraphWindow(cand.graph, "After Rule Application"); SaveResultDialog.Show(settings.filer, cand); }
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { if (e.ClickCount >= 2) { var rs = _settings.rulesets[_opt.ruleSetIndex]; object[] tempRuleObj = _settings.filer.Open( rs.rulesDir + rs.ruleFileNames[_opt.ruleNumber - 1]); SearchIO.addAndShowRuleWindow(tempRuleObj, "Rule for Option " + _opt.optionNumber + " from RuleSet " + _opt.ruleSetIndex + " Rule #" + _opt.ruleNumber); } base.OnPreviewMouseDown(e); }
protected override void Run() { var setupWin = new RandomStartDialog(this); setupWin.ShowDialog(); if (Cancel) { return; } var userChoose = new RandomChooseRCA(seedGraph, rulesets, numOfCalls, display); var cand = userChoose.GenerateOneCandidate(); SearchIO.addAndShowGraphWindow(cand.graph, "After Rule Application"); SaveResultDialog.Show(settings.filer, cand); }
public searchProcessController(int processNum) { if (Program.settings.searchControllerInMain) { this.MdiParent = Program.main; } InitializeComponent(); searchThread = new Thread(new ThreadStart(Program.runSearchProcess)); this.Text = "Search Process #" + processNum.ToString(); searchThread.Name = "S" + processNum.ToString() + "> "; priorityComboBox.SelectedIndex = 0; SearchIO.setVerbosity(searchThread.Name, Program.settings.defaultVerbosity); verbosityComboBox.SelectedIndex = Program.settings.defaultVerbosity; processTimer.Tick += new EventHandler(updateSPCDisplay); processTimer.Interval = getIntervalFromVerbosity(); }
public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display) { SearchIO.output("initializing generation:", 4); this.numOfRuleSets = _rulesets.GetLength(0); this.rulesets = new ruleSet[numOfRuleSets]; for (int i = 0; i != numOfRuleSets; i++) { rulesets[i] = _rulesets[i].copy(); } SearchIO.output("There are " + numOfRuleSets + " rule sets.", 4); this.seed = new candidate(_seed.copy(), numOfRuleSets); SearchIO.output("Seed = " + seed.graph.name, 4); maxNumOfCalls = _maxNumOfCalls; this.display = _display; SearchIO.output("It is " + display.ToString() + " that the SearchIO will be displayed.", 4); }
public void OpenOnExecuted(object sender, ExecutedRoutedEventArgs e) { var filename = ""; try { filename = getOpenFilename(GSApp.settings.WorkingDirAbsolute); } catch (FileNotFoundException fnfe) { SearchIO.output("File Not Found: " + fnfe); } if (!string.IsNullOrWhiteSpace(filename)) { OpenAndShow(filename); } }
public override int[] choose(List <option> options, candidate cand) { option.AssignOptionConfluence(options, cand, ConfluenceAnalysis.Full); SearchIO.output("There are " + options.Count + " recognized locations.", 2); if (options.Count == 0) { SearchIO.output("Sorry there are no rules recognized."); return(new[] { -2 }); } if (options.Count > settings.MaxRulesToDisplay) { SearchIO.output("Sorry there are too many rules to show."); return(new[] { -2 }); } SearchIO.output("Double-click on one to show the location.", 2); return(UserChooseWindow.PromptUser(options, settings, (cand.recipe.Count == 0))); }
/// <summary> /// Adds and shows a ruleset window. /// </summary> /// <param name="ruleSetObjects">The rule set objects.</param> /// <param name="title">The title.</param> public void addAndShowRuleSetWindow(object ruleSetObjects, string title) { if (main == null) { SearchIO.output("Cannot show ruleset, {0}, without GUI loaded.", title); } else if (main.Dispatcher.CheckAccess()) { main.addAndShowRuleSetWindow(ruleSetObjects, title); } else { main.Dispatcher.Invoke( (ThreadStart)(() => main.addAndShowRuleSetWindow(ruleSetObjects, title)) ); } }
/// <summary> /// Adds and shows a graph window. /// </summary> /// <param name = "graphObjects">The graph objects.</param> /// <param name = "title">The title.</param> public void addAndShowGraphWindow(object graphObjects, string title = "") { if (main == null) { SearchIO.output("Cannot show graph, {0}, without GUI loaded.", title); } else if (main.Dispatcher.CheckAccess()) { main.addAndShowGraphWindow(graphObjects, title); } else { main.Dispatcher.Invoke( (ThreadStart)(() => main.addAndShowGraphWindow(graphObjects, title)) ); } }