-
Imports:
tkinter
: Tkinter is the standard GUI library for Python. It provides classes for creating GUI applications.ttk
: Thettk
module provides access to the Tk themed widget set.messagebox
: This module provides a simple way to create message boxes.
-
Class Definition:
AHP_GUI
: This class represents the main application window for the AHP analysis.
-
Initialization (
__init__
method):- Sets up the main application window (
root
) with a title. - Defines the criteria and alternatives for the AHP analysis.
- Creates frames (
criteria_frame
andalternatives_frame
) to organize the input fields for criteria weights and alternative scores. - Initializes variables to store criteria weights (
criteria_weights
) and alternative scores (alternative_scores
). - Creates input fields (Entry widgets) for users to input criteria weights and alternative scores.
- Creates a "Calculate" button to trigger the AHP calculation process.
- Sets up the main application window (
-
Pairwise Comparison (
pairwise_comparison
method):- This method performs pairwise comparison of criteria weights.
- It creates a pairwise comparison matrix based on the user-provided weights.
- The pairwise comparison matrix is symmetric, and each element represents the ratio of the weight of one criterion to another.
-
Calculate Weights (
calculate_weights
method):- This method calculates the weights of criteria.
- It takes the pairwise comparison matrix as input.
- Uses NumPy's eigenvector function to calculate the principal eigenvector of the pairwise comparison matrix.
- Normalizes the eigenvector to obtain the criteria weights.
-
Normalize Scores (
normalize_scores
method):- This method normalizes the scores of alternatives.
- It ensures that the sum of scores adds up to 1, making them comparable.
- This step is necessary to standardize scores across different criteria.
-
Calculate (
calculate
method):- This method is executed when the user clicks the "Calculate" button.
- Retrieves criteria weights and alternative scores from the input fields.
- Performs pairwise comparisons for criteria weights.
- Calculates criteria weights.
- Normalizes alternative scores.
- Ranks alternatives based on their normalized scores.
- Displays the ranked alternatives in a message box.
-
Main Window:
- Creates the main Tkinter window (
root
). - Initializes the
AHP_GUI
class with the main window. - Enters the Tkinter event loop, allowing the GUI to respond to user interactions.
- Creates the main Tkinter window (
Overall, this code provides a graphical interface for users to input criteria weights and alternative scores, performs AHP calculations, and displays the ranked alternatives based on the analysis.