Exemple #1
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.");
     }
 }
Exemple #2
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);
        }