예제 #1
0
        public candidate ChooseAndApplyCarboxOptionUsingEstimator(candidate cand, Computation cpt, MessageClient clt, string runDir, int epoch)
        {
            option bestOpt      = null;
            var    bestProperty = Double.NegativeInfinity;
            var    options      = GetCarboxylOptions(cand);

            foreach (var opt in options)
            {
                var evalcand   = CopyAndApplyOption(opt, cand, true);
                var mol        = OBFunctions.designgraphtomol(evalcand.graph);
                var linkerName = AbstractAlgorithm.GetLinkerName(evalcand) + "-E" + epoch.ToString();
                var coeff      = Path.Combine(runDir, "data", "linker" + linkerName + ".coeff");
                var lmpdat     = Path.Combine(runDir, "data", "linker" + linkerName + ".lmpdat");
                Converter.moltoUFF(OBFunctions.designgraphtomol(evalcand.graph), coeff, lmpdat, false, 100);
                cpt.CalculateFeature(linkerName);
                var properpty = Convert.ToDouble(clt.SendMessage("[Predict]" + " " + linkerName));

                if (properpty > bestProperty)
                {
                    bestProperty = properpty;
                    bestOpt      = opt;
                }
            }
            Console.WriteLine("Best {0}", bestProperty);
            return(bestOpt == null ? null : CopyAndApplyOption(bestOpt, cand, true));
        }
        private void Generate()
        {
            Console.WriteLine("ddddd!");
            var agent     = new Algorithms.Random(settings);
            var linkerSet = new HashSet <string>();

            for (var e = 0; e < NUM_EPOCH; e++)
            {
                Console.WriteLine("Epoch: {0}", e);
                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;
                        while (cand == 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;
                            }
                            //var carboxOpt = agent.ChooseAndApplyOption(cand);
                            cand = agent.ChooseAndApplyCarboxOptionBestAngle(cand);
                            //cand = agent.ChooseAndApplyCarboxOptionUsingEstimator(cand, computation, client, _runDirectory);
                            if (cand == null)
                            {
                                Console.WriteLine("Fail on finding final carbox");
                            }
                        }

                        var candSmile  = OBFunctions.moltoSMILES(OBFunctions.designgraphtomol(cand.graph));
                        var linkerName = AbstractAlgorithm.GetLinkerName(cand);
                        //Console.WriteLine(candSmile);
                        Console.WriteLine(linkerName);
                        if (linkerSet.Contains(linkerName))
                        {
                            total_rule--;
                            continue;
                        }
                        linkerSet.Add(linkerName);
                        var coeff  = Path.Combine(_runDirectory, "data", "linker" + linkerName + ".coeff");
                        var lmpdat = Path.Combine(_runDirectory, "data", "linker" + linkerName + ".lmpdat");
                        agent.Converter.moltoUFF(OBFunctions.designgraphtomol(cand.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;
        }