예제 #1
0
        static void Main(string[] args)
        {
            int capacity;
            List <ReadCSV.item> knapsack;

            Phase1  phase1 = new Phase1();
            ReadCSV reader = new ReadCSV();
            Tuple <int, List <ReadCSV.item> > csv = reader.readCSV("k05.csv");

            capacity = csv.Item1;
            knapsack = csv.Item2;

            phase1.greedySolutions(capacity, knapsack);
        }
예제 #2
0
        public Tuple <decimal, decimal, string, string> optimized_2_Solution(int capacity, List <ReadCSV.item> knapsack, decimal minimumSolution)
        {
            Phase1    phase1 = new Phase1();
            Stopwatch timer  = new Stopwatch();

            timer.Start();
            var tup = phase1.maximumSolution(capacity, knapsack);

            timer.Stop();

            if (tup.Item4)
            {
                return(Tuple.Create(tup.Item1, tup.Item2, tup.Item3, Convert.ToString(timer.Elapsed)));
            }

            timer.Reset();

            decimal remainingValue = 0;

            node[] tree = new node[knapsack.Count];

            for (var i = 0; i < knapsack.Count; i++)
            {
                tree[i]         = new node(knapsack[i].name, i, knapsack[i].cost, knapsack[i].value);
                remainingValue += knapsack[i].value;
            }

            timer.Start();
            var timeMe = reCurse(capacity, tree, 0, "", 0, 0, remainingValue, minimumSolution, timer);

            if (timer.IsRunning)
            {
                timer.Stop();
            }

            return(Tuple.Create(timeMe.Item1, timeMe.Item2, timeMe.Item3, Convert.ToString(timer.Elapsed)));
        }
예제 #3
0
        public void printSolutions(int capacity, List <ReadCSV.item> knapsack, string filename)
        {
            node[] tree = new node[knapsack.Count];

            Phase1 phase1 = new Phase1();
            Phase2 phase2 = new Phase2();
            Phase3 phase3 = new Phase3();
            Phase5 phase5 = new Phase5();

            Tuple <decimal, decimal, decimal, decimal> greedySol = phase1.greedySolutions(capacity, knapsack);

            var minSol  = phase1.minimumSol(capacity, knapsack);
            var minSol2 = phase1.minimumSolution(capacity, knapsack);
            var maxSol  = phase1.maximumSolution(capacity, knapsack);

            var dumbSearch       = phase2.exhaustiveSolution(capacity, knapsack);
            var lessDumbSearch   = phase3.optimized_1_Solution(capacity, knapsack, minSol2.Item1);
            var leastDumbSearch  = phase5.optimized_2_Solution(capacity, knapsack.OrderByDescending(x => x.cost).ToList(), minSol2.Item1);
            var leastDumbSearch2 = phase5.optimized_2_Solution(capacity, knapsack.OrderByDescending(x => x.value).ToList(), minSol2.Item1);

            var txt = System.IO.Path.GetFileNameWithoutExtension(@filename);

            txt += ".txt";

            System.IO.File.WriteAllText(@txt, filename + "\n" +
                                        "Capacity: " + capacity + "\n" +
                                        "Best Greedy Min: " + minSol.Item1 + " " + minSol.Item2 + "\n" +
                                        minSol.Item3 + "\n" +
                                        "Best Greedy Max: " + maxSol.Item1 + " " + maxSol.Item2 + "\n" +
                                        maxSol.Item3 + "\n" +
                                        "Optimal Solution: " + dumbSearch.Item2 + " " + dumbSearch.Item1 + "\n" +
                                        dumbSearch.Item3 + "\n" +
                                        "Dumb Search: " + dumbSearch.Item4 + "\n" +
                                        "Less Dumb Time: " + lessDumbSearch.Item4 + "\n" +
                                        "Least Dumb Time By Ord by Cost : " + leastDumbSearch.Item4 + "\n" +
                                        "Least Dumb Time By Ord by Value: " + leastDumbSearch2.Item4);
        }
예제 #4
0
        static void Main(string[] args)
        {
            int capacity;
            List <ReadCSV.item> knapsack;

            Console.Write("Enter .csv to read: ");
            string filename = Console.ReadLine();

            Phase1  phase1 = new Phase1();
            Phase2  phase2 = new Phase2();
            Phase3  phase3 = new Phase3();
            Phase4  phase4 = new Phase4();
            ReadCSV reader = new ReadCSV();
            Tuple <int, List <ReadCSV.item> > csv = reader.readCSV(filename);

            capacity = csv.Item1;
            knapsack = csv.Item2;

            /*phase1.greedySolutions(capacity, knapsack);
             * phase2.exhaustiveSolution(capacity, knapsack);
             * phase3.optimized_1_Solution(capacity, knapsack);
             */
            phase4.printSolutions(capacity, knapsack, filename);
        }