Exemple #1
0
        private Result ILS(SCP problem)
        {
            List <Tuple <double, SCPSolution> > history = new List <Tuple <double, SCPSolution> >();
            bool     validity = false;
            int      iteratin = 0;
            TimeSpan elapsed  = new TimeSpan();
            double   cost     = 0;

            while (iteratin++ < 5)
            {
                IConstructiveHeuristic grasp = new SCPGRASP(0.9, 1e-9);
                cost = grasp.Execute(problem.Clone());
                SmartLocalSearch scpLS = new SmartLocalSearch();
                cost    = scpLS.Execute(grasp.Problem);
                elapsed = scpLS.Elapsed;
                history.Add(new Tuple <double, SCPSolution>(cost, scpLS.OptimumSultion.Clone()));
            }

            ((SCP)scpParser.Problem).Solution = history.OrderBy(h => h.Item1).ToList().FirstOrDefault().Item2;
            validity = SolutionValidity();

            Assert.AreEqual(validity, true);

            Result r = new UnitTest.Result();

            r.Time = elapsed.Milliseconds;
            r.Cost = cost;
            return(r);
        }
Exemple #2
0
        public double Execute(IProblem problem, bool vertical)
        {
            _problem = (SCP)problem;
            if (vertical)
            {
                VerticalSelection();
            }
            else
            {
                HorizantalSelection();
            }

            OptimumSultion = RemoveRedundantSet((SCPSolution)OptimumSultion);
            if (IsFeasible((SCPSolution)OptimumSultion) == false)
            {
                _problem.Solution = null;
            }
            else
            {
                _problem.Solution = (SCPSolution)OptimumSultion;
            }

            improve();

            return(_problem.Solution.Cost);
        }
        private void button6_Click_1(object sender, EventArgs e)

        {
            string user, pass;

            user = SCU.Text;
            pass = SCP.Text;
            user.Trim();
            pass.Trim();
            idC = checkerC(user, pass);
            if (idC == -1)
            {
                MessageBox.Show("Wrong Username Or Password");
                SCU.Clear();
                SCP.Clear();
            }
            else

            {
                Form2 f2 = new Form2();
                this.Hide();
                f2.ShowDialog();
                this.Close();
            }
        }
Exemple #4
0
        public static string Capture(List <string> parameters)
        {
            if (parameters != null && parameters.Count == 2)
            {
                string name = parameters[0].Trim().ToLower();
                SCP    scp  = GameManager.Instance.GetSCP(name);

                if (scp != null)
                {
                    int index;
                    if (!int.TryParse(parameters[1], out index))
                    {
                        return("usage:\n" +
                               "capture <name> <cellnumber>");
                    }

                    SCPManager manager = GameManager.Instance.GetComponent <SCPManager>();

                    if (manager.CaptureSCP(scp.Name, GameManager.Instance.FindCell(index)))
                    {
                        return($"Captured {scp.Name}, moved into cell {index}");
                    }
                    else
                    {
                        return($"Capture of {scp.Name} unsuccessful!");
                    }
                }
                else
                {
                    return($"{name} not found!");
                }
            }
            return("usage:\n" +
                   "capture <name> <cellnumber>");
        }
Exemple #5
0
 public Cell(DangerLevel cellLevel, int index, GameObject block, int spt, SCP cellInhabitant = null)
 {
     this.cellLevel      = cellLevel;
     this.cellInhabitant = cellInhabitant;
     this.index          = index;
     this.cellBlock      = block;
     this.spot           = spt;
     isFilled            = false;
 }
Exemple #6
0
        private double BudgetPlanning()
        {
            List <SCPSet>         sets       = new List <SCPSet>();
            List <SCPAttribute>   attributes = new List <SCPAttribute>();
            List <HashSet <int> > subsets    = new List <HashSet <int> >();

            subsets = SubsetMatrix();

            foreach (var set in subsets)
            {
                List <SCPSet> neighbors = _problem.Source.GetNeighbors(set.ToArray());
                if (neighbors.Count > 0)
                {
                    neighbors.ForEach(s =>
                    {
                        sets.Add(s);
                    });
                }
            }

            FindCardinalityInSet(sets);


            sets.ForEach(s => s.Attributes.ForEach(a1 =>
            {
                if (_losted.Exists(l => l.Item3 == a1.Tag))
                {
                    if (attributes.Exists(a2 => a1.Tag == a2.Tag) == false)
                    {
                        attributes.Add(a1);
                    }
                }
            }));

            SCPDataSet source = new SCPDataSet()
            {
                Sets = sets, Attributes = attributes
            };

            source.Resetset();
            SCP subproblem = new SCP(new MatrixSize()
            {
                X = attributes.Count, Y = sets.Count
            })
            {
                Source = source
            };

            IConstructiveHeuristic fog = new SCPGRASP(0.9, 1e-9);
            double cost = fog.Execute(subproblem);

            _cadidate = subproblem.Solution.Sets;
            return(cost);
        }
Exemple #7
0
        ///<summary>
        /// Returns  first repetition of SCP (Sterilizer Configuration Segment) - creates it if necessary
        ///</summary>
        public SCP GetSCP()
        {
            SCP ret = null;

            try {
                ret = (SCP)this.GetStructure("SCP");
            } catch (HL7Exception e) {
                HapiLogFactory.GetHapiLog(GetType()).Error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
                throw new System.Exception("An unexpected error ocurred", e);
            }
            return(ret);
        }
Exemple #8
0
        public void Test()
        {
            SCP        problem = (SCP)scpParser.Problem;
            SCPDataSet source  = (SCPDataSet)problem.Source.Clone();
            List <Tuple <SCPAttribute, SCPSet> > panel = new List <Tuple <SCPAttribute, SCPSet> >();

            source.Attributes.ForEach(a =>
            {
                a.Cost = a.GetCheapestCost();
                panel.Add(new Tuple <SCPAttribute, SCPSet>(a, a.GetCheapestSet()));
            });



            int         covered   = 0;
            SCPSolution solution2 = new SCPSolution();

            while (covered < source.Attributes.Count)
            {
                source.Attributes = source.Attributes.OrderByDescending(a => a.Cost).ToList();
                source.Attributes.ForEach(a1 =>
                {
                    a1.Visit = false;
                    a1.UsedIn.ForEach(s =>
                    {
                        s.Weight = s.Cost / s.Frequency;
                    });
                    a1.UsedIn = a1.UsedIn.OrderBy(ui => ui.Weight).ToList();
                });

                SCPSet set = source.Attributes.Where(at => at.Visit == false).First().UsedIn.First();

                set.Attributes.ForEach(a =>
                {
                    if (a.Visit == false)
                    {
                        a.Visit = true;
                        covered++;
                        a.UsedIn.ForEach(s => s.Frequency--);
                    }
                });
                if (set.Visit == false)
                {
                    solution2.Sets.Add(set);
                }
                set.Visit = true;
            }


            RemoveRedundantSet(solution2);

            bool result = IsFeasible(solution2, problem);
        }
Exemple #9
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private bool SolutionValidity()
        {
            SCP           problem     = (SCP)scpParser.Problem;
            HashSet <int> problem_att = new HashSet <int>();

            problem.Source.Attributes.ForEach(a => problem_att.Add(a.Tag));

            HashSet <int> solution_att = new HashSet <int>();

            problem.Solution.USet.ForEach(a => solution_att.Add(a));

            return(problem_att.IsSubsetOf(solution_att));
        }
Exemple #10
0
        private bool IsFeasible(SCPSolution solution, SCP problem)
        {
            if (solution.Sets.Count <= 0)
            {
                return(false);
            }
            #region Step#1 Exhustive test
            List <int> attributes = new List <int>();
            solution.Sets.ForEach(s => s.Attributes.ForEach(a => attributes.Add(a.Tag)));
            attributes = attributes.OrderBy(a => a).ToList();
            for (int i = 1; i < attributes.Count; i++)
            {
                if (attributes[i] - attributes[i - 1] > 1)
                {
                    return(false);
                }
            }
            #endregion

            #region Step#2 Formulation test nx(n-1)/2
            int n    = problem.Matrix.Size.X;
            int sum1 = n * (n + 1) / 2;

            int seed = attributes[0];
            int sum2 = seed;
            for (int i = 1; i < attributes.Count; i++)
            {
                if (attributes[i] != seed)
                {
                    seed  = attributes[i];
                    sum2 += seed;
                }
            }
            if (sum2 != sum1)
            {
                return(false);
            }
            #endregion

            #region Step#3 Hashing test
            int[] list = new int[n];
            foreach (int item in attributes)
            {
                list[item - 1] = item;
            }
            #endregion

            return(true);
        }
Exemple #11
0
        public SCP GetSCP(string name)
        {
            SCP targetSCP = null;

            for (int i = 0; i < scps.Keys.Count; i++)
            {
                if (targetSCP != null)
                {
                    break;
                }

                targetSCP = scps[(DangerLevel)i].Find(scp => scp.Name == name);
            }
            return(targetSCP);
        }
Exemple #12
0
        /// <summary>
        /// Method return false if cell is invalid, returns true if succeeded
        /// </summary>
        /// <param name="floorNumber"></param>
        /// <param name="roomNumber"></param>
        /// <param name="newSCP"></param>
        /// <returns></returns>
        public bool AddSCP(int floorNumber, int cellNumber, SCP newSCP)
        {
            if (floorNumber > floorCount ||
                cellNumber > 3 ||
                ((CellBlock)(floors[floorNumber].GetComponent <Floor>())).Cells[cellNumber].IsFilled)
            {
                return(false);
            }

            else
            {
                ((CellBlock)(floors[floorNumber].GetComponent <Floor>())).Cells[cellNumber].ContainSCP(newSCP);
                return(true);
            }
        }
 public Main()
 {
     //equips
     summonbox = new BrokenPrinter();
     reactor   = new UnstableQuantumReactor();
     lum       = new Lumpkin();
     //items
     grinder = new Item();
     key     = new BrokenKeycard();
     nokia   = new Nokia();
     root    = new Root();
     trinket = new MechanicalTrinket();
     pillow  = new Pillow();
     sundial = new Sundial();
     scp     = new SCP();
 }
Exemple #14
0
        public double Execute(IProblem problem)
        {
            _problem = (SCP)problem;

            HorizantalSelection();

            FSolution = RemoveRedundantSet((SCPSolution)FSolution);
            if (IsFeasible((SCPSolution)FSolution) == false)
            {
                _problem.Solution = null;
            }
            else
            {
                _problem.Solution = (SCPSolution)FSolution;
            }

            return(_problem.Solution.Cost);
        }
Exemple #15
0
    void BreachContainment(SCP scip)
    {
        int penaltyMod = ((int)scip.DL * 20) + Random.Range(0, 40);

        scip.ContainmentCell.CellInhabitant = null;
        scip.ContainmentCell = null;
        scip.Contained       = false;

        money.GainMoney(-penaltyMod);

        for (int i = 0; i < penaltyMod / 40; i++)
        {
            sManager.StaffDied(
                building.GetComponent <Containment>().Floors[scip.ContainmentCell.Index / 10].GetComponent <CellBlock>().residentStaff[Random.Range(0,
                                                                                                                                                    building.GetComponent <Containment>().Floors[scip.ContainmentCell.Index / 10].GetComponent <CellBlock>().residentStaff.Count)].GetInstanceID()
                );
        }

        GameObject.FindGameObjectWithTag("Terminal").GetComponent <Terminal>().WriteToDisplay("WARNING: " + " has escaped from confinenment! This has cost the site " + penaltyMod + " dollars in damages and we lost " + " staff members.");
    }
Exemple #16
0
        public void Read(string path)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            string str = file.ReadLine();

            _problem = new SCP(new MatrixSize()
            {
                X = int.Parse((str.Trim().Split(' ')[0])), Y = int.Parse(str.Trim().Split(' ')[1])
            });
            _problem.Source = new SCPDataSet();
            str             = "";
            for (int index = 0; index < _problem.Matrix.Size.Y;)
            {
                int read = file.Read();

                if (read == 32 || read == 10)
                {
                    if (str != "")
                    {
                        SCPSet set = new SCPSet()
                        {
                            Tag = ++index, Cost = int.Parse(str)
                        };
                        _problem.Source.Sets.Add(set);
                        str = "";
                    }
                    continue;
                }
                else
                {
                    str += (read - 48);
                }
            }

            DataBinding(true, 0, _problem.Matrix.Size.X, file);
        }
Exemple #17
0
        public double Execute(IProblem problem)
        {
            sp.Restart();
            _problem = (SCP)problem;
            int coveredatt, setCount, attCount;

            coveredatt = 0;
            List <SCPSet>       sets       = _problem.Source.Sets;
            List <SCPAttribute> attributes = _problem.Source.Attributes;

            setCount = sets.Count;
            attCount = attributes.Count;

            double c_min = sets.Min(a => a.Cost);

            while (coveredatt < attCount)
            {
                double        e_min = 0, e_max = 0, e_limit = 0;
                SCPSet        k;
                List <SCPSet> rcl = new List <SCPSet>();

                for (int i = 0; i < setCount; i++)
                {
                    if (sets[i].Frequency > 0)
                    {
                        sets[i].Weight = sets[i].Frequency / (1 + sets[i].Cost - c_min);
                        if (i > 0)
                        {
                            if (sets[i].Weight < e_min)
                            {
                                e_min = sets[i].Weight;
                            }
                            if (sets[i].Weight > e_max)
                            {
                                e_max = sets[i].Weight;
                            }
                        }
                        else
                        {
                            e_min = e_max = sets[i].Weight;
                        }
                    }
                }

                e_limit = e_min + _alpha * (e_max - e_min);

                for (int i = 0; i < setCount; i++)
                {
                    if (sets[i].Frequency > 0 && sets[i].Weight + _epsilon >= e_limit)
                    {
                        rcl.Add(sets[i]);
                    }
                }

                if (rcl.Count == 0)
                {
                    return(0);
                }

                k = rcl[new Random().Next(0, rcl.Count) % rcl.Count];
                _solution.Add(k);
                _totalCost += k.Cost;
                k.Attributes.ForEach(a1 =>
                {
                    SCPAttribute attribute = _problem.Source.Attributes.Find(a2 => a2.Tag == a1.Tag);
                    if (attribute != null)
                    {
                        if (attribute.Visit == false)
                        {
                            coveredatt++;
                            attribute.UsedIn.ForEach(s1 =>
                            {
                                s1.Frequency--;
                            });
                        }
                        attribute.Visit = true;
                    }
                });
            }
            sp.Stop();
            _problem.Solution = new SCPSolution()
            {
                Sets = _solution
            };
            return(_totalCost);
        }
Exemple #18
0
 /// <summary>
 /// Used to add a new SCP object to the room
 /// </summary>
 /// <param name="scpType">The type that the new SCP is</param>
 /// <param name="newSCP">The actual scp object</param>
 public void AddScp(DangerLevel scpType, SCP newSCP)
 => scps[scpType].Add(newSCP);
Exemple #19
0
 ///<summary>
 ///Removes the given SCP
 ///</summary>
 public void RemoveSCP(SCP toRemove)
 {
     this.RemoveStructure("SCP", toRemove);
 }
Exemple #20
0
 /// <summary>
 /// Adds an SCP to the Cell
 /// </summary>
 /// <param name="scip">the SCP to be placed in the Cell</param>
 public void ContainSCP(SCP scip)
 {
     cellInhabitant = scip;
     isFilled       = true;
 }
Exemple #21
0
 private void Initializer(IProblem problem)
 {
     _problem      = (SCP)problem;
     _currSolution = _problem.Solution.Clone();
     _opSolution   = _currSolution.Clone();
 }
Exemple #22
0
 private void Initializer(IProblem problem)
 {
     _problem = (SCP)problem;
     _problem.MarkPrimeSets();
     _collections.Add(_problem.Solution.Clone());
 }