Exemple #1
0
    public void Test_Case_PowerSet1_City0()
    {
        // Arrange
        SetFunctions setFunctions = new SetFunctions();
        QuickSort    quickSort    = new QuickSort();

        (double, double)[] cityMap = { (0, 0), (0, 3), (3, 3) };
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            SetFunctions setFunctions = new SetFunctions();
            TSPFunction  tspFunctions = new TSPFunction();
            QuickSort    quickSort    = new QuickSort();
            FileReader   fileReader   = new FileReader();

            (double, double)[] cityMap = fileReader.ReadFile(@"C:\Users\lacap\Desktop\Paul\Cloud Folders Git\Algorithm Analysis\Programming Assignments\Week 15 Programming Asssignment\TestCases\Test_Case_04.txt");
Exemple #3
0
    public void PowerSet_Test()
    {
        // Arrange
        SetFunctions setFunctions = new SetFunctions();

        int[] set = { 1, 2, 3, 4 };

        // Act
        QuickSort quickSort = new QuickSort();

        List <int?>[] powerSet = setFunctions.OrderedPowerSet(set);
        quickSort.Sort(powerSet, 0, powerSet.Length - 1);

        // Assert
        Assert.Equal(15, powerSet.Length);
    }
Exemple #4
0
        public double BellmanHeldKarp(Graph graph)
        {
            SetFunctions setFunctions = new SetFunctions();

            int[] index = CreateIndexSet(graph._vertices.Length);

            // Get the power sets
            List <int?>[] powerSetInd = setFunctions.RemoveNonBase(setFunctions.OrderedPowerSet(index), 0);

            // Initialize A and n's
            int n   = index.Length;
            int bar = 0;

            // Initialize the A to the size of the column (length of the powerset) and size of the row (length of the destination)
            double[,] A = new double[powerSetInd.Length, n - 1];

            // base Case |S| = 2
            for (int i = 0; i < powerSetInd.Length; i++)
            {
                // Initialization over we now reach Subsets with 3 or more elements
                if (powerSetInd[i].Count > 2)
                {
                    bar = i;
                    break;
                }

                else if (powerSetInd[i].Count == 2)
                {
                    // Set size only is 2: which is the source (0) and the destination (1) so our j is the destination is the second element in the powerset
                    int j = (int)powerSetInd[i][1];

                    // i is so that we are in the row with proper size 2 power set, j as i said is the destination
                    // cij means the c1j in the pseudocode: graph._vertices[0] is the default while 0 ia the source and j is the dest
                    // j - 1 for the array because we always remove the source element which is zero
                    A[i, j - 1] = graph._vertices[0]._neighbor[j];
                }
            }

            // Subproblems
            // bar is our checkpoint marker in the initial stage
            // note in the pseudocode its the subproblem size but we made the powerset in a way that iterating through it will pass through all the subproblems from smallest to largest
            for (int i = bar; i < powerSetInd.Length; i++)
            {
                // the iteration of the powerset (the second for loop of the pesudocode is actually combined into one)
                List <int?> S = powerSetInd[i];

                // Iterate the destinations (j) and we must not include 0 thats why we start at 1
                for (int e = 1; e < S.Count; e++)
                {
                    // j stores the iteration of the destination
                    int j = (int)S[e];

                    //A[i, j] = 0; // The min Corollary 21.2
                    // Set up the get minimum in the iteration

                    // The index we want from S
                    int k_index = 0;
                    // The winning distance
                    double minDistance = 9999999;

                    // the winning BellmanRecurrence Index
                    int br_winner = 0;

                    // iterate through the current power set but do not include 0 and j for k
                    for (int kk = 0; kk < S.Count; kk++)
                    {
                        // the current value of k in the iteration
                        int?k = S[kk];
                        if (k != 0 && k != j)
                        {
                            // Get the location of the S-{j} in the power set
                            int ind = BellmanRecurrence(powerSetInd, S, j);

                            // i is the proper location of row in the corresponds to the right power set, j is the destination
                            // ind  the proper location of row in the corresponds to the right S-{j}, k is the one in the psudocode
                            // and graph_vert... k j is the length from k to j
                            //A[i,j] = A[ind, (int) k] + graph._vertices[(int) k]._neighbor[j];

                            // this is not finished we need to change this to get the minimum value for A[i,j] among the values of k in the iteration
                            double minCandidate = A[ind, (int)k - 1] + graph._vertices[(int)k]._neighbor[j];
                            if (minCandidate < minDistance)
                            {
                                minDistance = minCandidate;
                                k_index     = (int)k;
                                br_winner   = ind;
                            }
                        }
                    }

                    A[i, j - 1] = A[br_winner, k_index - 1] + graph._vertices[k_index]._neighbor[j];
                }
            }
            // From destination 1 to n-1 we need to see which has the minimum using the largest subset V
            int    V_index          = powerSetInd.Length - 1;
            double superMinDistance = 9999999;
            double superMinCandidate;

            for (int fj = 1; fj < n; fj++)
            {
                superMinCandidate = A[V_index, fj - 1] + graph._vertices[fj]._neighbor[0];

                if (superMinCandidate < superMinDistance)
                {
                    superMinDistance = superMinCandidate;
                }
            }
            return(superMinDistance);
        }
Exemple #5
0
 public ClientWrapper(API api, IEventHandler eventHandler)
 {
     Setter = new SetFunctions(eventHandler);
     Getter = new GetFunctions(eventHandler);
 }