//Display the results in the required format
        public static Models.ResultFromrun formatOutput(pathData minValue)
        {
            nodesOnpath = String.Empty;

            pathData result = minValue;


            minpathValue = result.minValue.ToString();


            String sReplace = result.rows.Replace(",", String.Empty);

            char[] s1 = sReplace.ToCharArray();

            foreach (var item in s1)
            {
                nodesOnpath += (Int32.Parse(item.ToString()) + 1).ToString();
            }



            if (s1.Length == ColumnGlobal)
            {
                TravelledFromOneEndofMatrixToNext = "Yes";
            }
            else
            {
                TravelledFromOneEndofMatrixToNext = "No";
            }


            ResultFromrun Finalresult = new ResultFromrun(minpathValue, nodesOnpath, TravelledFromOneEndofMatrixToNext);

            return(Finalresult);
        }
        public static ResultFromrun Main(int prows, int pcolumns, int[,] pData, int pMaximumAllowedWeight)
        {
            //Step0: Source matrix
            sourcematrix             = pData;
            MaximumAllowedPathWeight = pMaximumAllowedWeight;
            //  Step1: Enter the Rows in the matrix

            int rows = prows;

            RowGlobal = rows;



            //Step2: Enter the Columns in the matrix

            int columns = pcolumns;

            ColumnGlobal = columns;



            //Step3: Generate the matrix
            //GenerateUserInput(rows, columns,sourcematrix); //Not needed....


            //Step3: Split a matrix with many columns into smaller solution sets to solve.
            pathData minValue = SplitMatrixintoSmallerPieces(rows, columns);


            //Only do this computation if user specified a Maxiumem allowed value for path data
            if (MaximumAllowedPathWeight > 0)
            {
                //Step5: Limit path value to stop it if it exceeds a maximum allowed path weight

                minValue = CheckAndStopIfPathWeightLimitExceeded(minValue, MaximumAllowedPathWeight);
            }


            //Step5: Display the results, in the required format
            ResultFromrun finalResult = formatOutput(minValue);

            return(finalResult);
        }
Exemple #3
0
        public static ResultFromrun Main(int prows, int pcolumns, int[,] pData)
        {
            //Step0: Source matrix
            sourcematrix = pData;

            //  Step1: Enter the Rows in the matrix

            int rows = prows;

            RowGlobal = rows;



            //Step2: Enter the Columns in the matrix

            int columns = pcolumns;

            ColumnGlobal = columns;



            //Step3: Generate the matrix
            //GenerateUserInput(rows, columns,sourcematrix); //Not needed....



            //Step4: Generate all possible paths  and then return the smallest value path.
            var minValue = GenerateSmallestPossiblePaths(rows, columns);



            //Step5: Display the results, in the required format
            ResultFromrun finalResult = formatOutput(minValue);

            return(finalResult);
        }