Esempio n. 1
0
 private void lastSol_Click(object sender, EventArgs e)
 {
     Cursor     = Cursors.WaitCursor;
     solutionBS = new BindingSource();
     if (comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
     {
         solutionBS.DataSource = DBSolution.GetByID(numberOfSolutions);
     }
     else
     {
         string pName = ((Profs)comboBox1.Items[comboBox1.SelectedIndex]).ProfName;
         solutionBS = new BindingSource
         {
             DataSource = DBSolution.GetByProfID(pName, numberOfSolutions)
         };
     }
     solIndex = numberOfSolutions;
     solutionViewGrid.DataSource     = solutionBS;
     bindingNavigator1.BindingSource = solutionBS;
     label2.Text = "";
     for (int y = 0; y < Notes[solIndex - 1].Count; y++)
     {
         label2.Text += Convert.ToString(Notes[solIndex - 1][y]);
     }
     SolUpDown.ValueChanged += null;
     SolUpDown.Value         = solIndex;
     SolUpDown.ValueChanged += SolUpDown_ValueChanged;
     nextSol.Enabled         = false;
     lastSol.Enabled         = false;
     firstSol.Enabled        = true;
     prevSol.Enabled         = true;
     Cursor = Cursors.Default;
 }
Esempio n. 2
0
 private void SolUpDown_ValueChanged(object sender, EventArgs e)
 {
     Cursor      = Cursors.WaitCursor;
     solutionBS  = new BindingSource();
     solIndex    = Convert.ToInt16(SolUpDown.Value);
     label2.Text = "";
     if (solIndex < 1)
     {
         return;
     }
     if (Notes == null)
     {
         return;
     }
     for (int y = 0; y < Notes[solIndex - 1].Count; y++)
     {
         label2.Text += Convert.ToString(Notes[solIndex - 1][y]);
     }
     if (comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
     {
         solutionBS.DataSource = DBSolution.GetByID(solIndex);
     }
     else
     {
         string pName = ((Profs)comboBox1.Items[comboBox1.SelectedIndex]).ProfName;
         solutionBS.DataSource = DBSolution.GetByProfID(pName, solIndex);
     }
     solutionViewGrid.DataSource     = solutionBS;
     bindingNavigator1.BindingSource = solutionBS;
     if (solIndex == 1)
     {
         firstSol.Enabled = false;
         prevSol.Enabled  = false;
     }
     else
     {
         firstSol.Enabled = true;
         prevSol.Enabled  = true;
     }
     if (solIndex == numberOfSolutions)
     {
         nextSol.Enabled = false;
         lastSol.Enabled = false;
     }
     else
     {
         nextSol.Enabled = true;
         lastSol.Enabled = true;
     }
     Cursor = Cursors.Default;
 }
Esempio n. 3
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     Cursor = Cursors.WaitCursor;
     if (comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
     {
         SolUpDown_ValueChanged(null, null);
     }
     else
     {
         if (numberOfSolutions > 0)
         {
             string pName = ((Profs)comboBox1.Items[comboBox1.SelectedIndex]).ProfName;
             solutionBS = new BindingSource
             {
                 DataSource = DBSolution.GetByProfID(pName, (int)SolUpDown.Value)
             };
             solutionViewGrid.DataSource     = solutionBS;
             bindingNavigator1.BindingSource = solutionBS;
         }
     }
     Cursor = Cursors.Default;
 }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="net"></param>
        /// <param name="course"></param>
        /// <param name="noOfCourses"></param>
        private void Solve(CourseNetwork net, IntVariable[] course, int noOfCourses)
        {
            //net.Objective = course[0];
            Solver solver;

            if (radioButton6.Checked)
            {
                solver = new IterativeBranchAndBoundSearch(net, Solver.Minimize);
            }
            else if (radioButton4.Checked)
            {
                solver = new DefaultSolver(net, Solver.Minimize);
                solver.SolverStrategy = (Solver.StrategyMethod)numericUpDown3.Value;
            }
            else if (radioButton3.Checked)
            {
                //int opt = Solver.BETTER;
                solver = new TabooSearch(net, Solver.Minimize);
            }
            else
            {
                net.Objective = course[0];
                solver        = new SimulatedAnneallingSearch(net, Solver.Minimize);
            }

            long timer = DateTime.Now.Ticks;
            int  count = 1;

            //StreamWriter sw = new StreamWriter(".\\out.txt");
            DBSolution.DeleteAll();
            Notes = new IList[(int)numericUpDown1.Value];
            Solution bestSolution = null;

            for (solver.Start((long)numericUpDown2.Value); solver.WaitNext(); solver.Resume())
            {
                Solution sol = solver.Solution;
                if (count == 1)
                {
                    bestSolution = sol;
                }
                else
                {
                    if (bestSolution != null)
                    {
                        if (sol.Weight > bestSolution.Weight)
                        {
                            bestSolution = sol;
                        }
                    }
                }
                Notes[count - 1] = new ArrayList {
                    "Weight= " + sol.Weight + "\n"
                };
                for (int i = 0; i < net.Professors.Count; i++)
                {
                    int pcount = 0;
                    for (int j = 0; j < net.Variables.Count; j++)
                    {
                        if (!((Variable)net.Variables[j]).IsValueType)
                        {
                            if (sol.GetIntValue(((Variable)net.Variables[j])) == i)
                            {
                                pcount++;
                            }
                        }
                    }
                    if (pcount < ((Professor)net.Professors[i]).RealNoOfCourses)
                    {
                        Notes[count - 1].Add("Prof. " + ((Professor)net.Professors[i]).ToString() +
                                             " not consistent.. needs " +
                                             (((Professor)net.Professors[i]).RealNoOfCourses - pcount) +
                                             " assignment(s) more!!" + "\n");
                        // sw.WriteLine("Prof. " + ((Professor)net.Professors[i]).toString() + " not consistent.. needs " +
                        //     (((Professor)net.Professors[i]).Courses - pcount) + " assignment(s) more!!");
                    }
                }

                Console.Out.WriteLine();
                for (int i = 0; i < noOfCourses; i++)
                {
                    //if (!((Variable)(net.Variables[i])).IsValueType)
                    //{
                    //sw.WriteLine(course[i].Name + " = " + ((Professor)net.Professors[sol.getIntValue(course[i])]).Name);
                    var dbSolution = new DBSolution
                    {
                        SolutionID    = count,
                        CourseName    = course[i].Name,
                        ProfessorName =
                            ((Professor)net.Professors[sol.GetIntValue(course[i])]).Name
                    };
                    dbSolution.AddSolution();
                    //}
                }
                //sw.WriteLine("=================================");
                count++;
                //if (solver is DefaultSolver)
                //{
                if (count == numericUpDown1.Value + 1)
                {
                    break;
                }
                //}
                //else
                //{
                //   break;
                //}
            }
            Console.WriteLine(bestSolution);
            timer = DateTime.Now.Ticks - timer;
            //sw.WriteLine("timer: " + timer);
            //sw.WriteLine("Count=" + count);
            //sw.Close();
            solutionBS = new BindingSource();
            if (count > 1)
            {
                solutionBS.DataSource           = DBSolution.GetByID(1);
                bindingNavigator1.BindingSource = solutionBS;
                solutionViewGrid.DataSource     = solutionBS;
                solIndex          = 1;
                firstSol.Enabled  = false;
                prevSol.Enabled   = false;
                SolUpDown.Minimum = 1;
                SolUpDown.Maximum = count - 1;
                SolUpDown.Value   = 1;
                SolUpDown.Enabled = true;
                if (count == 2)
                {
                    nextSol.Enabled = false;
                    lastSol.Enabled = false;
                }
                else
                {
                    nextSol.Enabled = true;
                    lastSol.Enabled = true;
                }
            }
            else
            {
                SolUpDown.Minimum = 0;
                SolUpDown.Maximum = 0;
                SolUpDown.Enabled = false;
                firstSol.Enabled  = false;
                prevSol.Enabled   = false;
                nextSol.Enabled   = false;
                lastSol.Enabled   = false;
            }
            label2.Text = "";
            if (count > 1)
            {
                for (int y = 0; y < Notes[solIndex - 1].Count; y++)
                {
                    label2.Text += Convert.ToString(Notes[solIndex - 1][y]);
                }
            }
            numberOfSolutions = count - 1;
            solutionViewGrid.Columns[2].Visible = false;
            if (timer / 10000 / 1000 == 0)
            {
                MessageBox.Show((count - 1) + " Solution(s) found in " + timer / 1000.0 + " MS");
            }
            else
            {
                MessageBox.Show((count - 1) + " Solution(s) found in " + timer / 10000.0 / 1000 + " second(s)");
            }
        }