public candidate[] getFinalCand(Deterministic agent) { var opts = AbstractAlgorithm.GetCarboxylOptions(Cand); var finals = new candidate[opts.Count]; for (var i = 0; i < finals.Length; i++) { finals[i] = agent.CopyAndApplyOption(opts[i], Cand, true); } return(finals); }
public BFSNode[] getChildren(Deterministic agent) { var opts = AbstractAlgorithm.GetAvailableOptions(Cand); var nodes = new BFSNode[opts.Count]; for (var i = 0; i < nodes.Length; i++) { var child = agent.CopyAndApplyOption(opts[i], Cand, true); nodes[i] = new BFSNode(child, Depth + 1); } return(nodes); }
private void button3_Click(object sender, EventArgs e) { ChangeEnabled(false); this.btnStop.Enabled = true; this.ConsoleWrite("Resolving cube...", true); // this.alg = new AlgorithmRandom(3000000); this.alg = (AbstractAlgorithm)cmbAlgorithm.SelectedItem; alg.Resolve(this.cubeA, this.cubeB); while (!alg.IsCompleted) { // this.alg.doEvents(); this.updateAlgStatus(alg.cubeStat); this.ConsoleWrite(alg.Status(), false); Application.DoEvents(); this.Refresh(); System.Threading.Thread.Sleep(500); } // Show solution ChangeEnabled(true); string sMoves = ""; if (alg.cubeMatch != null) { foreach (Move m in this.alg.winnerMoves) { sMoves += m.ToString() + " "; } this.ConsoleWrite(sMoves, false); btnSolution.Enabled = true; } else { btnSolution.Enabled = false; if (this.alg.IsCanceled) { this.ConsoleWrite("Resolution canceled by user", false); } else { this.ConsoleWrite("There is not solution for this algorithm", false); } } this.updateAlgStatus(alg.cubeMatch); this.Refresh(); this.btnStop.Enabled = false; }
public ActionResult Solve(FormCollection fc) { AbstractAlgorithm algorithm = null; switch (fc.GetValue("Algorithm").AttemptedValue) { case "KernighanLin": GraphProblemDb.CurrentProblem.Algorithm = Algorithm.KernighanLin; algorithm = new KernighanLin(); GraphProblemDb.CurrentProblem = algorithm.FindCommunityStructure(GraphProblemDb.CurrentProblem.Graph); break; case "GirvanNewman": GraphProblemDb.CurrentProblem.Algorithm = Algorithm.GirvanNewman; algorithm = new GirvanNewman(); GraphProblemDb.CurrentProblem = algorithm.FindCommunityStructure(GraphProblemDb.CurrentProblem.Graph); break; } return(RedirectToAction("GraphListResult", "GraphListResult", GraphProblemDb.CurrentProblem)); }
public void Run(AbstractAlgorithm _task, string name = "") { task = _task; history = new HistoryChart { DotsCount = 200, Max = 1, Lines = { new HistoryChartValueLine { DataFunction ={ Color = Color.Blue } } }, Dock = DockStyle.Bottom }; mainChart = new Chart { ChartAreas = { new ChartArea { AxisY = { Maximum = MaxValue, Minimum = MinValue } } }, Dock = DockStyle.Fill }; form = new Form() { Text = name, Size = new Size(800, 600), FormBorderStyle = FormBorderStyle.FixedDialog, }; form.Controls.Add(mainChart); if (HistoryGraph) { form.Controls.Add(history); } bool algorithmExited = false; task.UpdateCharts += (series, index) => { try { form.BeginInvoke(new Action <List <Series> >(UpdateCharts), series); } catch { } }; task.RegisterError += args => { try { form.BeginInvoke(new Action <double>(UpdateHistory), args); } catch { } }; task.Exit += () => { algorithmExited = true; try { form.BeginInvoke(new Action(form.Close)); } catch { } }; form.FormClosing += (s, a) => { task.RequestExit(); a.Cancel = !algorithmExited; }; new Action(task.Run).BeginInvoke(null, null); //Application.Run(form); form.ShowDialog(); }
protected AbstractAlgorithm Parent; // how we can call f /// <summary> /// Implements a function for performing random rollout to the given parameters. /// </summary> /// <param name="width">How many rollouts to run.</param> /// <param name="depth">How deep each rollout should go.</param> /// <param name="parent">The class used to manipulate the molecule.</param> protected AbstractEvaluation(int width, int depth, AbstractAlgorithm parent) { Width = width; Depth = depth; Parent = parent; }
public RolloutEvaluation(int width, int depth, AbstractAlgorithm parent) : base(width, depth, parent) { _random = new Random(AbstractAlgorithm.Settings); }
private void GenerateFixed() { var agent = new Algorithms.Random(settings); var linkerBeforeCarboxDict = new Dictionary <string, candidate>(); for (var t = 0; t < NUM_TRAIL; t++) { Console.WriteLine("Trail: {0}", t); for (var total_rule = TOTAL_RULE_MIN; total_rule < TOTAL_RULE_MAX + 1; total_rule++) { candidate cand = null; candidate finalCand = null; while (cand == null || finalCand == null) { cand = Seed.copy(); Console.WriteLine("Total Intermediate Rules: {0}", total_rule); for (var step = 0; step < total_rule; step++) { cand = agent.ChooseAndApplyOption(cand); if (cand == null) { Console.WriteLine("Fail on step {0}", step + 1); break; } } if (cand == null) { continue; } finalCand = agent.ChooseAndApplyCarboxOption(cand); if (finalCand == null) { Console.WriteLine("Fail on finding final carbox"); } } var linkerName = AbstractAlgorithm.GetLinkerName(cand); Console.WriteLine(linkerName); if (linkerBeforeCarboxDict.ContainsKey(linkerName)) { total_rule--; continue; } linkerBeforeCarboxDict[linkerName] = cand; } } Console.WriteLine(linkerBeforeCarboxDict.Count); for (var e = 0; e < NUM_EPOCH; e++) { Console.WriteLine("Epoch: {0}", e); foreach (var item in linkerBeforeCarboxDict) { var submitCand = agent.ChooseAndApplyCarboxOptionUsingEstimator(item.Value, computation, client, _runDirectory, e); //cand = agent.ChooseAndApplyCarboxOptionBestAngle(item.Value()); //cand = agent.ChooseAndApplyCarboxOptionUsingEstimator(item.Value(), computation, client, _runDirectory); if (submitCand == null) { Console.WriteLine("Fail on finding final carbox, should never happen"); Environment.Exit(0); } var linkerName = AbstractAlgorithm.GetLinkerName(submitCand) + "-E" + e.ToString(); var coeff = Path.Combine(_runDirectory, "data", "linker" + linkerName + ".coeff"); var lmpdat = Path.Combine(_runDirectory, "data", "linker" + linkerName + ".lmpdat"); agent.Converter.moltoUFF(OBFunctions.designgraphtomol(submitCand.graph), coeff, lmpdat, false, 100); double piority = 0; if (CARBOXTYPE == "estimator") { piority = -Convert.ToDouble(client.SendMessage("[Predict]" + " " + linkerName)); } else { piority = AbstractAlgorithm.Rand.NextDouble(); computation.CalculateFeature(linkerName); } //mutex.WaitOne(); jobBuffer.Add(linkerName, piority, e); //mutex.ReleaseMutex(); } if (CARBOXTYPE == "estimator") { while (true) { var on_simulation = jobBuffer.Num_simulating(); if (on_simulation == 0) { break; } Console.WriteLine("Wait for current {0} linkers to finish simulation....", on_simulation); Thread.Sleep(10000); } client.SendMessage("[FitModel]"); } } allSubmitFlag = true; }
public void Run(AbstractAlgorithm _task, int rows = 1, int columns = 1, string name = "") { task = _task; var height = 100.0f / rows; var width = 100.0f / columns; var table = new TableLayoutPanel(); table.ColumnStyles.Clear(); table.RowCount = 2; table.ColumnCount = 2; table.RowStyles.Clear(); for (int i = 0; i < rows; i++) { table.RowStyles.Add(new RowStyle { SizeType = SizeType.Percent, Height = height }); } table.ColumnStyles.Clear(); for (int i = 0; i < columns; i++) { table.ColumnStyles.Add(new ColumnStyle { SizeType = SizeType.Percent, Width = width }); } Charts = new Chart[rows, columns]; for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { Charts[row, column] = new Chart(); Charts[row, column].ChartAreas.Add(new ChartArea()); Charts[row, column].Dock = DockStyle.Fill; table.Controls.Add(Charts[row, column], column, row); } } form = new Form() { Text = name, Size = new Size(800, 600), FormBorderStyle = FormBorderStyle.FixedDialog, WindowState = FormWindowState.Maximized }; table.Dock = DockStyle.Fill; table.Size = form.ClientSize; form.Controls.Add(table); bool algorithmExited = false; task.UpdateCharts += (series, index) => { // try { form.BeginInvoke(new Action <List <Series>, int>(UpdateCharts), series, index); // } catch { } }; task.Exit += () => { algorithmExited = true; try { form.BeginInvoke(new Action(form.Close)); } catch { } }; form.FormClosing += (s, a) => { task.RequestExit(); a.Cancel = !algorithmExited; }; new Action(task.Run).BeginInvoke(null, null); Application.Run(form); }