Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
1
Indexable
Never
import numpy as np

# Define your criteria and alternatives
criteria = ["Criterion 1", "Criterion 2", "Criterion 3", ...]
alternatives = ["Alternative 1", "Alternative 2", "Alternative 3", ...]

# Create a matrix to input pairwise comparison values (criteria x criteria)
pairwise_matrix = np.zeros((len(criteria), len(criteria)))

# Input your pairwise comparison values (on a scale from 1 to 9, where 1 means equal importance and 9 means extreme importance)
pairwise_matrix[0][1] = 3  # Example: Criterion 1 is moderately more important than Criterion 2
pairwise_matrix[1][0] = 1/3  # Reverse of the above comparison

# Repeat the above process for all pairwise comparisons

# Calculate the criteria weights
criteria_weights = np.mean(pairwise_matrix, axis=1) / np.sum(np.mean(pairwise_matrix, axis=1))

# Create a matrix to input pairwise comparison values (alternatives x alternatives)
pairwise_matrix_alternatives = np.zeros((len(alternatives), len(alternatives)))

# Input your pairwise comparison values for alternatives
# Repeat the above process for all pairwise comparisons among alternatives

# Calculate the alternative weights
alternative_weights = np.mean(pairwise_matrix_alternatives, axis=1) / np.sum(np.mean(pairwise_matrix_alternatives, axis=1))

# Print criteria and alternative weights
print("Criteria Weights:", criteria_weights)
print("Alternative Weights:", alternative_weights)