Exemple #1
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string str = LoggerUtils.GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());

            MessageBox.Show(str, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            LoggerUtils.Error(str);
        }
Exemple #2
0
        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            string str = LoggerUtils.GetExceptionMsg(e.Exception, e.ToString());

            MessageBox.Show(str, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            LoggerUtils.Error(str);
        }
        private void LoadProgram()
        {
            try
            {
                m_program = new Control(args: new List <string>()
                {
                    m_maxSolutions.ToString(), "--const", $"rows={m_rows}", "--const", $"cols={m_cols}"
                });

                LoggerUtils.Log("Loading definition files");

                m_program.Load(ClingoConstants.ItemDefinitionFile);
                m_program.Load(ClingoConstants.IndustryGeneratorFile);

                LoggerUtils.Log("Grounding program");

                var parts = new List <Tuple <string, List <Symbol> > >()
                {
                    new Tuple <string, List <Symbol> >("base", new List <Symbol>())
                };
                m_program.Ground(parts);

                LoggerUtils.Log("Solving program");
                m_solver = m_program.Solve(yield: true);
            }
            catch (Exception ex)
            {
                LoggerUtils.Error(ex, "cannot load logic program: ");
            }
        }
        /// <summary>
        /// Create a new clingo program and starts the searching
        /// </summary>
        /// <param name="maxSolutions">The number of solutions that clingo will find. <c>0</c> for no limit</param>
        /// <param name="rows">The number of rows in the parcel</param>
        /// <param name="cols">The number of cols in the parcel</param>
        public void StartProgram(int maxSolutions, int rows, int cols)
        {
            try
            {
                if (clingo == null)
                {
                    LoadClingo();
                }

                m_maxSolutions = maxSolutions;
                m_rows         = rows;
                m_cols         = cols;

                LoadProgram();

                m_modelHandle = m_solver.GetEnumerator() as ModelEnumerator;

                m_results = new List <Region>();

                IsAlive    = true;
                IsFinished = false;
            }
            catch (Exception ex)
            {
                LoggerUtils.Error(ex);
            }
        }
 private void LoadClingo()
 {
     try
     {
         //LoggerUtils.Log($"Loading clingo from {ClingoConstants.ClingoPath}");
         clingo = new Clingo(ClingoConstants.ClingoPath);
     }
     catch (Exception ex)
     {
         LoggerUtils.Error(ex, "cannot load clingo: ");
     }
 }
        private Model NewSolution()
        {
            try
            {
                if (m_modelHandle.MoveNext())
                {
                    return(m_modelHandle.Current);
                }

                return(null);
            }
            catch (Exception ex)
            {
                LoggerUtils.Error(ex, "cannot get new solution: ");
                return(null);
            }
        }