public RandomBaseline(GlobalSettings settings) : base(settings) { RequireSeed = true; RequiredNumRuleSets = 1; AutoPlay = true; Seed = new candidate(OBFunctions.tagconvexhullpoints(settings.seed), settings.numOfRuleSets); _runDirectory = Path.Combine(settings.OutputDirAbs, "RandomBaseline"); if (Directory.Exists(_runDirectory)) { Directory.Delete(_runDirectory, true); } Directory.CreateDirectory(_runDirectory); var learnDirectory = Path.Combine(settings.OutputDirAbs, "morfLearn"); computation = new Computation(_runDirectory, learnDirectory, "point", "stiff"); writer = new StreamWriter(Path.Combine(_runDirectory, "RandomBaseline.txt")); jobBuffer = new JobBuffer(_runDirectory); agent = new Algorithms.Random(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; }