public void AddJob(DeviceId deviceId, Jobs.Job job)
 {
     _jobBuffer.Add(deviceId, job);
 }
        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;
        }