public static void Run()
        {
            UpdateExperimentResultsAndClear();
            int experimentCount = 0;

            int.TryParse(ConfigurationManager.AppSettings["ExperimentCount"], out experimentCount);
            bool flag = false;
            List <TblProbabilityExperiment> lst = ProbabilityExperimentDS.GetForExperiment(experimentCount);

            foreach (TblProbabilityExperiment tblExp in lst)
            {
                DatabaseManagement    dbManagement = new DatabaseManagement();
                TblDatabaseManagement newDB        = dbManagement.CreateForExperiment(
                    "exp_" + tblExp.SupportProbability + "_" + tblExp.ConfidenceProbability
                    , tblExp.MaxArity
                    , tblExp.MaxVariablesInRelation
                    , tblExp.SupportProbability
                    , tblExp.ConfidenceProbability
                    , tblExp.ProbabilityIncreaseByArity
                    );
                if (newDB != null)
                {
                    flag = true;
                    tblExp.FkDatabaseId = newDB.Id;
                    ProbabilityExperimentDS.Update(tblExp);
                }
            }
            if (flag && MQGenerator.IsAutoRunJobs)
            {
                MQGenerator.StartDBProcess();
            }
        }
Пример #2
0
        public static int StartSendMQToSolver()
        {
            List <TblMetaquery> lstMQ = MetaqueryDS.GetMQForSendToSolver();

            int  count = 0;
            bool doStartExpandMQProcess = false, doStartIncreaseDBArity = false;

            while (lstMQ.Count > 0)
            {
                RabbitProducer <string> producer = null;
                foreach (TblMetaquery tblMetaquery in lstMQ)
                {
                    TblDatabaseManagement curDB = tblMetaquery.TblDatabaseManagement;
                    if (!curDB.ForExperiment)
                    {
                        if (producer == null)
                        {
                            string queueToMQSolverName = ConfigurationManager.AppSettings["QueueToMQSolverName"];
                            producer = new RabbitProducer <string>(queueToMQSolverName);
                        }
                        Metaquery metaquery = new Metaquery(tblMetaquery.Metaquery);
                        //שליחה לסולבר
                        SendMQMessage message = new SendMQMessage()
                        {
                            ID = tblMetaquery.Id,
                            SupportThreshold    = curDB.SupportThreshold,
                            ConfidenceThreshold = curDB.ConfidenceThreshold,
                            Head = metaquery.Head.Variables,
                            Body = metaquery.Body.GetVariables()
                        };

                        string strMessage = message.ToJson();                          //JsonConvert.SerializeObject(message);
                        producer.SendMessage(strMessage);

                        MetaqueryDS.UpdateStatus(tblMetaquery, StatusMQ.WaitingToSolver);
                    }
                    else
                    {
                        RandomMQProbability randomMQProbability = new RandomMQProbability(curDB.SupportProbability.Value, curDB.ConfidenceProbability.Value, curDB.ProbabilityIncreaseByArity ?? 0, tblMetaquery.Arity);
                        tblMetaquery.FkResult = (int)randomMQProbability.GetRandomResultMQ();

                        StatusMQ statusMQ = (tblMetaquery.IsExpanded || tblMetaquery.Arity == tblMetaquery.TblDatabaseManagement.MaxArity ? StatusMQ.Done : StatusMQ.WaitingToExpand);
                        MetaqueryDS.UpdateStatus(tblMetaquery, statusMQ);

                        if (statusMQ == StatusMQ.WaitingToExpand)
                        {
                            doStartExpandMQProcess = true;
                        }
                        else if (statusMQ == StatusMQ.Done)
                        {
                            doStartIncreaseDBArity = true;
                        }
                    }
                    count++;
                }
                lstMQ = MetaqueryDS.GetMQForSendToSolver();
            }
            if (MQGenerator.IsAutoRunJobs)
            {
                if (doStartExpandMQProcess)
                {
                    MQGenerator.StartExpandMQProcess();
                }
                else if (doStartIncreaseDBArity)
                {
                    MQGenerator.StartIncreaseDBArity();
                }
            }
            return(count);
        }
Пример #3
0
        public static void OnGetMessageFromSolver(string strMessage)
        {
            MQMessage message = null;

            if (strMessage.Contains("Result"))            //strMessage is MQResultMessage
            {
                message = JsonConvert.DeserializeObject <MQResultMessage>(strMessage);
            }
            else             //strMessage is MQAssignmentResultMessage
            {
                message = JsonConvert.DeserializeObject <MQAssignmentResultMessage>(strMessage);
            }

            int          metaqueryID  = message.ID;
            TblMetaquery tblMetaquery = MetaqueryDS.GetByID(metaqueryID);

            try
            {
                if (tblMetaquery == null)
                {
                    throw new UnknownMetaqueryException(string.Format("There is an unknown metaquery id sent from solver. message id: {0}. MQ Solver message :", metaqueryID, message.ToString()));
                }

                if (message is MQResultMessage)
                {
                    MQResultMessage resultMessage = message as MQResultMessage;
                    tblMetaquery.FkResult = (int)resultMessage.Result;
                    StatusMQ statusMQ = (tblMetaquery.IsExpanded || tblMetaquery.Arity == tblMetaquery.TblDatabaseManagement.MaxArity ? StatusMQ.Done : StatusMQ.WaitingToExpand);
                    MetaqueryDS.UpdateStatus(tblMetaquery, statusMQ);
                    bool execSendMail = bool.Parse(ConfigurationManager.AppSettings["ExecSendMail"]);
                    if (execSendMail)
                    {
                        MQGeneratorMail.SendResultMail(tblMetaquery);
                    }

                    if (MQGenerator.IsAutoRunJobs)
                    {
                        if (statusMQ == StatusMQ.WaitingToExpand)
                        {
                            MQGenerator.StartExpandMQProcess();
                        }
                        else if (statusMQ == StatusMQ.Done)
                        {
                            MQGenerator.StartIncreaseDBArity();
                        }
                    }
                }
                else if (message is MQAssignmentResultMessage)
                {
                    MQAssignmentResultMessage assignmentResultMessage = message as MQAssignmentResultMessage;
                    TblMetaqueriesResult      tblMetaqueriesResult    = new TblMetaqueriesResult()
                    {
                        FkMetaqueryId   = metaqueryID,
                        Assignment      = assignmentResultMessage.Assignment,
                        ConfidenceValue = assignmentResultMessage.ConfidenceValue,
                        SupportValue    = assignmentResultMessage.SupportValue
                    };
                    MetaqueryResultDS.Create(tblMetaqueriesResult);

                    bool execSendMail = bool.Parse(ConfigurationManager.AppSettings["ExecSendMail"]);
                    if (execSendMail)
                    {
                        MQGeneratorMail.SendAssignmentMail(tblMetaqueriesResult, tblMetaquery.Metaquery);
                    }
                    if (MQGenerator.IsAutoRunJobs && !tblMetaquery.IsExpanded)
                    {
                        MQGenerator.StartExpandMQProcess();
                    }
                }
                else
                {
                    throw new UnknownMetaqueryException("There is an unknown metaquery sent from solver. MQ Solver message :" + message.ToString());
                }
            }
            catch (Exception ex)
            {
                MQGeneratorMail.SendExceptionMail(ex);
            }
        }