Пример #1
0
        private void OpenFile()
        {
            OpenFileDialog f = new OpenFileDialog();

            f.Title  = "Load previously learned data...";
            f.Filter = "QLearned Files (*.qlearned)|*.qlearned";

            QLearned o = null;

            if (f.ShowDialog() == DialogResult.OK)
            {
                WriteOutput("Opening " + f.FileName + "...");
                EnableControls(false);
                using (Stream stream = File.Open(f.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    try
                    {
                        BinaryFormatter bFormatter = new BinaryFormatter();
                        o = (QLearned)bFormatter.Deserialize(stream);
                        stream.Close();

                        if (o != null)
                        {
                            if (algo == null || algo.GetType().Name != o.algo)
                            {
                                QAlgoPlugins.SelectedItem = o.algo;
                            }
                            if (state == null || state.GetType().Name != o.state)
                            {
                                QStatePlugins.SelectedItem = o.state;
                            }
                            agent = new QAgent(this, algo, state);
                            agent.Open(o);
                        }
                        else
                        {
                            popup("Unable to open data from " + f.FileName);
                        }
                    }
                    catch (Exception e)
                    {
                        stream.Close();
                        popup("Unable to open data from " + f.FileName + "\nDetails: " + e);
                    }
                }
            }
            EnableControls(true);
        }
Пример #2
0
 public void Open(QLearned o)
 {
     if (o.algo != currentAlgo.GetType().Name)
     {
         master.popup("QLearned file is for the QAlgo '" + o.algo + "', not the '" + currentAlgo.GetType().Name + "' currently selected.");
     }
     else if (o.state != initialState.GetType().Name)
     {
         master.popup("QLearned file is for the QState '" + o.state + "', not the '" + initialState.GetType().Name + "' currently selected.");
     }
     else
     {
         currentAlgo.Open(o.contents, initialState);
         WriteOutput("Learning data loaded.");
     }
 }
Пример #3
0
        private void SaveFile()
        {
            QLearned o = agent.Save();

            if (o == null)
            {
                popup("Nothing to save.");
            }
            else
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Title        = "Save learned data to...";
                dialog.Filter       = "QLearned Files (*.qlearned)|*.qlearned";
                dialog.FileName     = o.state + "_" + o.algo.Replace("_", "") + "_Learn" + o.learn + "_Discount" + o.discount + "_Explore" + o.explore + "_" + o.trials + "Trial" + (o.trials == 1? "":"s");
                dialog.AddExtension = true;


                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    WriteOutput("Saving to " + dialog.FileName);
                    EnableControls(false);

                    using (Stream stream = File.Open(dialog.FileName, FileMode.Create))
                    {
                        try
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            bFormatter.Serialize(stream, o);
                            stream.Close();
                            WriteOutput("Learning data saved to " + dialog.FileName);
                        }
                        catch (Exception e)
                        {
                            stream.Close();
                            WriteOutput("Error saving data: " + e);
                        }
                    }
                }
                EnableControls(true);
            }
        }
Пример #4
0
 public void Open(QLearned o)
 {
     if (o.algo != currentAlgo.GetType().Name) master.popup("QLearned file is for the QAlgo '" + o.algo + "', not the '" + currentAlgo.GetType().Name + "' currently selected.");
     else if (o.state != initialState.GetType().Name) master.popup("QLearned file is for the QState '" + o.state + "', not the '" + initialState.GetType().Name + "' currently selected.");
     else
     {
         currentAlgo.Open(o.contents, initialState);
         WriteOutput("Learning data loaded.");
     }
 }