AHP algorithm--java version

Source: Internet
Author: User

A self-written AHP simple algorithm, in fact, is some circular calculation, recorded, may be used in the future:

First understand what is the AHP


analytic Hierarchy process (Analytic Hierarchy Process, referred to as AHP) is the American Research Institute, Pittsburg University T. L. Professor Saaty in the early 1970s, AHP is a simple, flexible and practical multi-criteria decision-making method for quantitative analysis of qualitative problems. It is characterized by dividing the various factors in the complex problem into an orderly level of mutual connection, making it organized, according to the subjective judgment structure of certain objective reality (mainly 22 comparison), combining the objective judgment result of expert opinion and analyst directly and effectively, and quantitatively describe the importance of the comparison of one level element 22. Then, using the mathematical method qualitative analysis and quantitative analysis


The following is a simple implementation that contains consistency judgments

Import Java.util.scanner;public class AHP {/*1231/212/31/33/21 *61 1 1 4 1 1/21 1 2 4 1 1/21 1/2 1 5 3 1/21 /4 1/5 1 1/3 1/31 1 1/3 3 1 2 2 3 1 1 */public static void Main (string[] args) {System.out.println () ; Scanner Scanner = new Scanner (system.in); int n = scanner.nextint ();d ouble d[][] = new Double[n][n];d ouble temp[][] = new D ouble[n][n];for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) {Double stod = Stod (Scanner.next ());d [i][j] = s TOD;TEMP[I][J] = Stod;}} System.out.println ("The following is the Judgment Matrix");//Gets the judgment matrix for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) {System.out.printf (" %.2f\t ", D[i][j]);} System.out.println ();} 1. Sum System.out.println the Judgment matrix ("column add result");d ouble w1[] = new Double[n];for (int i = 0; i < n; i++) {for (int j = 0; J &L T N J + +) {W1[i] = W1[i] + d[j][i];} System.out.printf ("%.2f\t", W1[i]);} 2. Divide System.out.println (); for (int i = 0, i < n; i++) {for (int j = 0; J < N; j + +) {D[i][j] = D[i][j]/w1[j];}} System.ouT.println ("and the result of the first step of the plot method"); for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) {System.out.printf ("%.2f\t", d[i][ j]);} System.out.println ();} SYSTEM.OUT.PRINTLN ("Adding rows to the results obtained from the first step"); System.out.println ("Row add result");d ouble w2[] = new Double[n];for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) {W2 [i] = W2[i] + d[i][j];} System.out.printf ("\t%.2f\n", W2[i]);} System.out.println ("eigenvector solver Step One: Add all the results added to the above line:");d ouble sum = 0.0;for (int i = 0; i < n; i++) {sum + = W2[i];} System.out.printf ("result is sum = \t%.2f\n", sum); System.out.println ("divides the row result with sum to result in:");d ouble w3[] = new Double[n];for (int i = 0; I < n; i++) {W3[i] = w2[i]/sum; System.out.printf ("\t%.2f\n", W3[i]);} System.out.println (); System.out.println ("Use and accumulate method to calculate its maximum eigenvector is: W =");//The following is a checksum System.out.printf ("("); for (int i = 0; I < n; i++) {System.out.printf ("%.2f,", W3[i]);} System.out.printf (")"); System.out.println ("\NBW =");d ouble w4[] = new Double[n];for (int i = 0; I < n; i++) {for (int j = 0; J < N; j + +) {w4[I] = W4[i] + temp[i][j] * w3[j];} System.out.printf ("%.3f \ T", W4[i]);} System.out.println ("\ n----------------------------------------");d ouble sum2 = 0.0;for (int i = 0; i < n; i++) {sum2 = Sum2 + w4[i];} System.out.printf ("Get sum2\t%.2f\n", sum2); System.out.println ("Maximum eigenvector is:");d ouble result = 0.0;for (int i = 0; I < n; i++) {result = result + W4[i]/(6 * w3[i]);} System.out.printf ("%.2f \ n", result); System.out.println ("\ n judgment Matrix consistency Indicator" ( Consistency Index);d ouble CI = (result-n)/(n-1); System.out.printf ("%.2f \ n", CI); SYSTEM.OUT.PRINTLN ("random consistency ratio c.r." ( Consistency Ratio). */* * N 1 2 3 4 5 6 7 8 9 11RI 0 0 0.58 0.90 1.12 1.24 1.32 1.41 1.45 1.49 1.51 general, when the consistency ratio <0 .1 when the degree of inconsistency within the allowable range, it can be normalized eigenvector as a weight vector, or to reconstruct the comparison matrix, to be adjusted */double RI = 0.0;switch (n) {case 0:ri=0;break;case 1:ri=0;break ; case 2:ri=0;break;case 3:ri=0.58;break;case 4:ri=0.90;break;case 5:ri=1.12;break;case 6:RI=1.24;break;case 7:RI= 1.32;break;default:break;} System.out.printf ("C.R =%.")2f \ n ", Ci/ri); Scanner.close ();} public static double Stod (String s) {string[] p = s.split ("/"); if (P.length > 1) {return double.parsedouble (p[0])/Dou Ble.parsedouble (p[1]);} return double.parsedouble (s);}}
This topic is because I have a homework to use, in order to avoid a large number of operations each time, hereby wrote a program to achieve, the students need to copy their own code to calculate (⊙o⊙) Oh.

AHP algorithm--java version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.