public PlanogramOptimizerEncog(Item[] items, SimulationSettings simSettings, UpdateUINonRLMCallback updateUI = null, UpdateStatusCallback updateStatus = null, SimulationCsvLogger logger = null, bool anneal = true)
        {
            updateStatus?.Invoke("Initializing...");

            //this.items = items;
            this.simSettings  = simSettings;
            this.logger       = logger;
            this.updateUI     = updateUI;
            this.updateStatus = updateStatus;

            network        = CreateNetwork();
            planogramScore = new PlanogramScore()
            {
                SimSettings = simSettings,
                Items       = items,
                UpdateUI    = updateUI,
                Logger      = logger
            };

            if (anneal)
            {
                train = new NeuralSimulatedAnnealing(network, planogramScore, 10, 2, (simSettings.SimType == SimulationType.Sessions) ?  1 : 10); // todo make the # of cycles an input for users?
            }
            else
            {
                train = new MLMethodGeneticAlgorithm(() => {
                    ((IMLResettable)network).Reset();
                    return(network);
                }, planogramScore, 500);
            }
        }
示例#2
0
        /// <summary>
        /// 检测是否有新版本
        /// </summary>
        /// <param name="build">当前版本</param>
        /// <returns>有新版本则返回软件信息,无新版本时则返回null</returns>
        public Soft checkUpdate(long build)
        {
            String  softID = ConfigurationManager.AppSettings["SoftID"];
            IniFile file   = new IniFile(String.Format("{0}/application.cache", Application.StartupPath));

            Soft soft = null;

            try
            {
                UpdateStatusCallback?.Invoke("正在连接服务器...", -1);
                soft = NetApi.GetSoft(Convert.ToInt32(softID), file.IniReadValue("AccessToken", "token"));
            }
            catch (System.Net.WebException ex)
            {
                UpdateStatusCallback?.Invoke("获取数据时发生异常:" + ex.Message, 1);
                return(null);
            }

            if (soft == null || soft.Build <= build)
            {
                UpdateStatusCallback?.Invoke("未发现新版本", 0);
                return(null);
            }

            UpdateStatusCallback?.Invoke("发现新版本!", -1);

            return(soft);
        }
示例#3
0
        /// <summary>
        /// 根据版本号下载更新包
        /// </summary>
        /// <param name="build">最新版更新包实体</param>
        private bool downloadPackage(Soft build)
        {
            IniFile file = new IniFile(String.Format("{0}/application.cache", Application.StartupPath));

            AppConfigHelper.RootPath = Application.StartupPath;

            String host = ConfigurationManager.AppSettings["domain"];
            String url  = String.Format("{0}/api/product/download/{1}.json?access_token={2}", host, build.Packages[0].Id, file.IniReadValue("AccessToken", "token"));

            UpdateStatusCallback?.Invoke("正在下载更新包...", -1);

            String fileName = build.Packages[0].Name + ".zip";

            System.Windows.Forms.ProgressBar prog = null;
            float percent = 0;

            try
            {
                System.Net.HttpWebRequest  Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
                System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
                long totalBytes = myrp.ContentLength;
                if (prog != null)
                {
                    prog.Maximum = (int)totalBytes;
                }
                System.IO.Stream st = myrp.GetResponseStream();
                System.IO.Stream so = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
                long             totalDownloadedByte = 0;
                byte[]           by = new byte[1024];
                int osize           = st.Read(by, 0, (int)by.Length);
                while (osize > 0)
                {
                    totalDownloadedByte = osize + totalDownloadedByte;
                    System.Windows.Forms.Application.DoEvents();
                    so.Write(by, 0, osize);
                    if (prog != null)
                    {
                        prog.Value = (int)totalDownloadedByte;
                    }
                    osize = st.Read(by, 0, (int)by.Length);

                    percent = (float)totalDownloadedByte / (float)totalBytes * 100;
                    UpdateStatusCallback?.Invoke("当前补丁下载进度" + percent.ToString() + "%", -1);
                    System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则text将因为循环执行太快而来不及显示信息
                }
                so.Close();
                st.Close();
            }
            catch (System.Exception e)
            {
                UpdateStatusCallback?.Invoke("下载失败:" + e.Message, 10);
                return(false);
            }
            UpdateStatusCallback?.Invoke("更新包下载完成,请稍候...", 0);

            return(true);
        }
示例#4
0
        public void mainServer_StatusChanged(object sender, StatusChangedEventArgs e)
        {
            // Call the method that updates the form
            var callback = new UpdateStatusCallback(this.UpdateStatus);

            callback(e.EventMessage);

            //this.Invoke(new UpdateStatusCallback(this.UpdateStatus), new object[] { e.EventMessage });
        }
示例#5
0
        /// <summary>
        /// Instantiates a new instance of the plangoram optimizer
        /// </summary>
        /// <param name="items">The dataset (items with their attributes and metrics) for the RLM to learn from</param>
        /// <param name="simSettings">Holds data which dictates what type of simulation to run and for how long. Also holds the weights metrics and other general settings</param>
        /// <param name="updateUI">Callback function for sending the results of the optimization for each session</param>
        /// <param name="updateStatus">Callback function for sending the current status of the RLM</param>
        /// <param name="logger">Logs the per session stats and allows users to download the CSV file after the training</param>
        /// <remarks>Used a callback instead of an event because we worry that the display might not keep up with the optimization. You can disable the display by setting it in the Simulation panel</remarks>
        public PlanogramOptimizer(Item[] items, RPOCSimpleSimSettings simSettings, UpdateUICallback updateUI = null, UpdateStatusCallback updateStatus = null, SimulationCsvLogger logger = null, string dbIdentifier = null, DataPersistenceProgressDelegate dataPersistProgress = null)
        {
            IsTrainingDone = false;

            this.logger      = logger;
            this.items       = items.ToArray();
            this.simSettings = simSettings;
            UpdateUI         = updateUI;
            UpdateStatus     = updateStatus;
            if (ENABLE_RLM_OUTPUT_LIMITER)
            {
                currentItemIndexes = new List <int>();
            }

            UpdateStatus?.Invoke("Initializing...");

            // creates the network (and the underlying DB) with a unique name to have a different network everytime you run a simulation
            IRlmDbData rlmDbData = new RlmDbDataSQLServer(dbIdentifier != null ? dbIdentifier : "RLM_planogram_" + Guid.NewGuid().ToString("N"));

            //IRlmDbData rlmDbData = new RlmDbDataPostgreSqlServer(dbIdentifier != null ? dbIdentifier : "RLM_planogram_" + Guid.NewGuid().ToString("N"));
            network = new RlmNetwork(rlmDbData);

            if (dataPersistProgress != null)
            {
                network.DataPersistenceProgress += dataPersistProgress;
            }

            // checks if the network structure already exists
            // if not then we proceed to define the inputs and outputs

            inputType = RLM.Enums.RlmInputType.Distinct;
            if (!network.LoadNetwork("planogram"))
            {
                string int32Type = typeof(Int32).ToString();

                var inputs = new List <RlmIO>();
                //inputs.Add(new RlmIO() { Name = "Shelf", DotNetType = int32Type, Min = 1, Max = simSettings.NumShelves, Type = RLM.Enums.RlmInputType.Linear });
                inputs.Add(new RlmIO()
                {
                    Name = "Slot", DotNetType = int32Type, Min = 1, Max = simSettings.NumSlots * simSettings.NumShelves, Type = inputType
                });

                var outputs = new List <RlmIO>();
                outputs.Add(new RlmIO()
                {
                    Name = "Item", DotNetType = int32Type, Min = 0, Max = this.items.Length - 1
                });

                // change Max to any number above 1 (and must not be go beyond the NumSlots value) to have multiple facings
                //outputs.Add(new RlmIO() { Name = "NumFacings", DotNetType = int32Type, Min = 1, Max = 1 });

                // creates the network
                network.NewNetwork("planogram", inputs, outputs);
            }
        }
示例#6
0
 private void UpdateStatus(string text)
 {
     if (this.button2.InvokeRequired)
     {
         UpdateStatusCallback callback = new UpdateStatusCallback(UpdateStatus);
         this.Invoke(callback, new object[] { text });
     }
     else
     {
         textBoxLog.Text = textBoxLog.Text + Environment.NewLine + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " " + text;
     }
 }
示例#7
0
 private void SetText(String status)
 {
     if (richTxtBoxStatus.InvokeRequired)
     {
         UpdateStatusCallback d = new UpdateStatusCallback(UpdateStatus);
         this.Invoke(d, new object[] { status });
     }
     else
     {
         richTxtBoxStatus.AppendText(status);
     }
 }
示例#8
0
 public void UpdateStatus(string strUpdate)
 {
     if (statusStrip1.InvokeRequired)
     {
         UpdateStatusCallback d = new UpdateStatusCallback(UpdateStatus);
         this.Invoke(d, new object[] { strUpdate });
     }
     else
     {
         DateTime dt = DateTime.Now;
         toolStripStatusLabel1.Text = dt.ToString() + " : " + strUpdate;
     }
 }
示例#9
0
        delegate void UpdateStatusCallback(string statusString, ushort progress);   // Thread safe

        public void UpdateStatus(string statusString, ushort progress)
        {
            if (InvokeRequired)
            {
                UpdateStatusCallback d = new UpdateStatusCallback(UpdateStatus);
                Invoke(d, new object[] { statusString, progress });
            }
            else
            {
                status.Text             = statusString;
                statusProgressBar.Value = progress;
                if (statusProgressBar.Value == 100)
                {
                    statusProgressBar.Visible = false;
                }
                else
                {
                    statusProgressBar.Visible = true;
                }
            }
        }
示例#10
0
        public FormMain()
        {
            InitializeComponent();
            this.Text = s_AppName;
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);

            m_updateStatusCallback = new UpdateStatusCallback(UpdateStatus);
            m_addFileMatchCallback = new AddFileMatchCallback(AddFileMatch);

            Type searchType = typeof(FileContentType);

            foreach (FileContentType type in Enum.GetValues(searchType))
            {
                if (type != FileContentType.None)
                {
                    cbFileContentType.Items.Add(type);
                }
            }

            SetDefaultConfig();
            ReadConfig();

            BindViews();
            LoadWindowState();

            try
            {
                lblVersion.Text = string.Format("Version: {0}", System.Diagnostics.Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion.ToString());
            }
            catch (SystemException ex)
            {
                Debug.WriteLine("[{0}][{1}]", ex.Source, ex.Message);
            }

            UpdateStatus(UpdateStatusType.STATUS_BUTTON, m_buttonActionLabels[System.Convert.ToInt32(Actions.Search)]);
        }
示例#11
0
文件: Main.cs 项目: tdwright/VoxSSD
 private void UpdateStatus(string status)
 {
     if (this.statusStrip1.InvokeRequired)
     {
         UpdateStatusCallback d = new UpdateStatusCallback(UpdateStatus);
         this.Invoke(d, new object[] { status });
     }
     else
     {
         toolStripStatusLabel1.Text = status;
     }
 }
示例#12
0
        /*public static void mainServer_StatusChanged(object sender, StatusChangedEventArgs e)
         * {
         *  // Call the method that updates the form
         *  Invoke(new UpdateStatusCallback(this.UpdateStatus), new object[] { e.EventMessage });
         * }*/

        private static void Invoke(UpdateStatusCallback updateStatusCallback, object[] v)
        {
            throw new NotImplementedException();
        }
示例#13
0
        public void UpdateStatus(Dictionary <string, string> status)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.queryStatusStrip.InvokeRequired)
            {
                UpdateStatusCallback d = new UpdateStatusCallback(UpdateStatus);
                try
                {
                    this.Invoke(d, new object[] { status });
                }
                catch
                {
                    Application.Exit();
                }
            }
            else
            {
                foreach (string key in status.Keys)
                {
                    switch (key)
                    {
                    case "machinesProcessingLabel":
                        this.machinesProcessingLabel.Text = status[key];
                        Debug.WriteLine("statusStrip: " + status[key]);
                        break;

                    case "queryStatusLabel":
                        this.queryStatusLabel.Text = status[key];
                        break;

                    case "taskBarItemProgressState":
                        TaskbarManager.Instance.SetProgressState((TaskbarProgressBarState)System.Enum.Parse(typeof(TaskbarProgressBarState), status[key]), windowHandle);
                        break;

                    case "taskBarItemProgressValue":
                        try
                        {
                            TaskbarManager.Instance.SetProgressValue(int.Parse(status[key]), (int)Core.machinesTotal, windowHandle);
                            toolStripProgressBar.Value   = int.Parse(status[key]);
                            toolStripProgressBar.Maximum = (int)Core.machinesTotal;
                        }
                        catch
                        {
                        }
                        break;

                    case "clearQueryBoxErrors":
                        clearQueryBoxErrors();
                        break;

                    case "highlightErrors":
                        Match match  = Regex.Match(status[key], @"(\d+?),(\d+?)");
                        int   line   = int.Parse(match.Groups[1].ToString());
                        int   column = int.Parse(match.Groups[2].ToString());
                        highlightError(line, column);
                        break;

                    case "machinesSuccessfulLabel":
                        this.machinesSuccessfulLabel.Text = status[key];
                        Debug.WriteLine("statusStrip: " + status[key]);
                        break;

                    case "machinesErrorLabel":
                        this.machinesErrorLabel.Text = status[key];
                        Debug.WriteLine("statusStrip: " + status[key]);
                        break;

                    case "returnMachinesSuccessMachinesList":
                        machinesSuccess.Add(status[key]);
                        Debug.WriteLine("Marking " + status[key] + " as success");
                        break;

                    case "returnMachinesErrorMachinesList":
                        machinesError.Add(status[key]);
                        Debug.WriteLine("Marking " + status[key] + " as error");
                        break;

                    case "totalMachinesLabel":
                        totalMachinesLabel.Text = string.Format("Total Machines: {0}", status[key]);
                        break;
                    }
                }
            }
        }
示例#14
0
 public void SetCallback(UpdateStatusCallback newCB)
 {
     callback = newCB;
 }
示例#15
0
 private void UnzipCompleted(object sender, ICSharpCode.SharpZipLib.Core.ScanEventArgs e)
 {
     UpdateStatusCallback?.Invoke(String.Format("正在解压:{0},已完成。", e.Name), -1);
 }
示例#16
0
 private void UnzipProgree(object sender, ICSharpCode.SharpZipLib.Core.ProgressEventArgs e)
 {
     UpdateStatusCallback?.Invoke(String.Format("正在解压:{0},已完成{1}%", e.Name, e.Processed), -1);
 }