Name | AnaHiePro JSON |
Version |
0.0.0.1
JSON |
| download |
home_page | https://github.com/danylevych/AnaHiePro |
Summary | "AnaHiePro" is a module that allows solving various tasks of systems analysis using the Analytic Hierarchy Process (AHP). |
upload_time | 2024-07-13 19:09:17 |
maintainer | None |
docs_url | None |
author | Oleh Danylevych |
requires_python | >=3.6 |
license | None |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<a href="" rel="noopener">
<img width=400px src="assets/img/title.png" alt="Project logo"></a>
</p>
<h1 align="center">AnaHiePro</h1>
<div align="center">
[]()
[](https://github.com/danylevych/AnaHiePro/issues)
[](https://github.com/danylevych/AnaHiePro/pulls)
[](/LICENSE)
</div>
---
<p>
<b>AnaHiePro</b> is a module that allows solving various tasks of systems analysis using the Analytic Hierarchy Process (AHP).
<br>
</p>
## 📝 Content
- [About](#about)
- [Getting Started](#getting_started)
- [Usage](#usage)
- [Authors](#authors)
## 🧐 About <a name = "about"></a>
<b>AnaHiePro</b> is a Python module designed to simplify the decision-making process by using the Analytic Hierarchy Process (AHP) method. This method allows you to structure complex problems in the form of a hierarchical model consisting of goals, criteria, and alternatives. AnaHiePro automatically calculates global priorities for the entire hierarchy.
The module provides a recursive traversal of the hierarchical tree, starting from the leaf nodes and moving up to the root. Each level of the hierarchy is processed by multiplying the matrix of local child vectors by the global parent vector, which allows you to determine the weight of each element at all levels. This makes AnaHiePro an ideal tool for analyzing complex systems and making informed decisions in a variety of fields, including business, project management, scientific research, and more.
## 🏁 Getting Started <a name="getting_started"></a>
<h4>These are simple instructions on how to install <b>AnaHiePro</b> on your PC and start using it.</h4>
### Installing
Open the terminal window (Linux and macOS) or command line (Windows). Then use the `pip` command to install the module:
```sh
pip install anahiepro
```
### Prerequisites
Before installing AnaHiePro, ensure you have Python 3.x and `pip` installed on your system. You can download the latest version of Python from [python.org](https://www.python.org/).
After loading you can use all AnaHiePro's functionality, down below you can see the simplest way of using AnaHiePro.
```py
from anahiepro.nodes import Problem, Criteria, Alternative
from anahiepro.models.model import Model
problem = Problem("Example Problem")
list_of_criterias = [
Criteria("Citeria_1"),
Criteria("Citeria_2"),
Criteria("Citeria_3")
]
alternatives = [
Alternative("Alternative_1"),
Alternative("Alternative_2")
]
model = Model(problem, list_of_criterias, alternatives)
print(model.show())
```
## 🎈 Usage <a name="usage"></a>
- [Pairwise comparison matrix](#pairwise_matrix)
- [Nodes](#nodes)
- [Models](#models)
- [Tools](#tools)
### Pairwise matrix <a name="pairwise_matrix"></a>
`PairwiseComparisonMatrix` represents the pairwise comparison matrix. A pairwise comparison matrix is a tool used in decision-making processes. It helps compare different options or criteria by evaluating them in pairs. Each element of the matrix represents the comparison result between two options or criteria.
#### Methods
| Method Name | Description |
|-------------------|---------------------------------------------------|
| `__init__(self, size, matrix)` | Initialize a pairwise comparison matrix with the given size or given matrix. |
| `set_comparison(self, i, j, value)` | Set the comparison value for the given indices. Might raise the `ValueError` exception when you try to set diagonal values to value, that not equal `1`. |
| `set_matrix(self, matrix)` | Set the entire matrix, ensuring it is a valid pairwise comparison matrix. Might raise the `ValueError` if the matrix is not consistent or not valid.|
| `get_matrix(self)` | Returns the current pairwise comparison matrix. |
| `calculate_priority_vector(self)` | Calculate the priority vector from the pairwise comparison matrix. |
| `calculate_consistency_ratio(self)` | Calculate the consistency ratio of the pairwise comparison matrix. |
| `__getitem__(self, key)` | Returns the value at the specified index in the matrix. |
| `__setitem__(self, key, value)` | Set the value at the specified index in the matrix. |
#### Example
```py
from anahiepro.pairwise import PairwiseComparisonMatrix
matrix = [
[1, 2, 3],
[1/2, 1, 2],
[1/3, 1/2, 1]
]
pairwise_matrix = PairwiseComparisonMatrix(matrix=matrix)
print(pairwise_matrix.get_matrix())
print("Consistency ratio:", pairwise_matrix.calculate_consistency_ratio())
print("Priority vector:", pairwise_matrix.calculate_priority_vector())
```
Output:
```
[[1. 2. 3. ]
[0.5 1. 2. ]
[0.33333333 0.5 1. ]]
Consistency ratio: 0.007933373029552656
Priority vector: [0.84679693 0.46601031 0.25645536]
```
### Nodes
AnaHiePro has three types of nodes: Problem, Criteria (also DummyCriteria, which use for normalizing the model) and Alternative. All of them is inherited from abstract class `Node`.
> **_NOTE:_** And we want to mentione that each class which is inhereted from `Node` has an id field.
#### Node class
As we mentioned before, `Node` is a basic class for `Problem`, `Criteria` and `Alternative`. Down below you can see all `Node`'s methods:
<br>
| Method Name | Description |
|-------------------|---------------------------------------------------|
| `__init__(self, name, parents, children, id, pcm)` | Initialize the `Node` object with given `name`, list of its `parents`, list of `children`, identifier (`id`) and pcm. |
| `get_name(self)` | Returns the name of the node. |
| `get_parents(self)` | Returns list of parents for the node. |
| `get_children(self)` | Returns list of children for the node. |
| `get_key(self)` | Returns the tuple object, which consists of name of a node and its id. |
| `add_child(self, child)` | Add `child` to the list of children. |
| `show(self)` | Returns str object, which represent all relations between nodes. |
| `compare(self, key: tuple)` | Compare the node with a given key, where `key` is a tuple object which has size that equal 2. `key[0]` is a name of node and `key[1]` is an identifier of the node. |
| `create_pcm(self)` | Create a pairwise comparison matrix (PCM) object for the node which shape is equal number of node's childrens. |
| `set_matrix(self, matrix)` | Attach given PCM to the node. If the `self.pcm` does not exist call the `create_pcm` method than checks if the shape of given matrix matchs, raise `VlalueError` if does not otherwise attach it. |
| `set_comparison(self, i, j, value)` | Set given `value` to the right place. Other words it is a wrapper above the `PairwiseComparisonMatrix`'s `set_comparison` method. |
| `get_priority_vector(self)` | Wrapper above PairwiseComparisonMatrix`'s `get_priority_vector` method. |
| `get_consistency_ratio(self)` | Wrapper above PairwiseComparisonMatrix`'s `get_consistency_ratio` method. |
| `get_pcm(self)` | Returns the pairwise comparison matrix of the node. |
| `__eq__(self, value)` | Compare two `Node`'s instance. |
| `def show(self)` | Show the node and its children in a hierarchical structure. |
| `__copy__(self)` | Copy the node. |
#### Problem class
`Problem` is a class that represents the problem that the user wants to solve. This class inherits from Node and has the same methods as its parent. However, it overrides some methods.
| Method Name | Description |
|-------------------|---------------------------------------------------|
| `__init__(self, name, children, pcm)` | Initialize the `Problem` object with given `name`, list of its childern and pairwise comparison matrix. |
The remaining methods are the same as in the `Node` class.
#### Criteria class
`Criteria` represents the criteria which will be used for selection. This class inherits form `Node` and has the same methods as his parrent, except of this it overrides some methods.
| Method Name | Description |
|-------------------|---------------------------------------------------|
| `__init__(self, name, children, pcm)` | Initialize the `Criteria` object with given `name`, list of its childern and pairwise comparison matrix. |
The remaining methods are the same as in the `Node` class.
#### DummyCriteria class
`DummyCriteria` class that inherited from `Criteria` it is used for normalizing problem in `VaryDepthModel`.
#### Alternative class
`Alternative` represents alternatives between which the selection occurs. Since `Alternative` is the final node in the hierarchy, it has no children, so the self.pcm field for it is deleted.
| Method Name | Description |
|-------------------|---------------------------------------------------|
| `__init__(self, name)` | Initialize the `Alternative` object with given `name`. |
| `create_pcm(self)` | Not implemented for reasons which were mentioned. |
| `set_matrix(self, matrix)` | Not implemented and raise `NotImplementedError` exception. |
| `set_comparison(self, i, j, value) | Not implemented and raise `NotImplementedError` exception. |
The remaining methods are the same as in the `Node` class.
#### Example
```py
from anahiepro.nodes import Problem, Criteria, Alternative
# Create instance of each classes.
problem = Problem("Example Problem")
criteria1 = Criteria("Criteria_1")
criteria2 = Criteria("Criteria_2")
alternative1 = Alternative("Alternative_1")
alternative2 = Alternative("Alternative_2")
# Linking each instances.
problem.add_child(criteria1)
problem.add_child(criteria2)
criteria1.add_child(alternative1)
criteria1.add_child(alternative2)
criteria2.add_child(alternative1)
criteria2.add_child(alternative2)
# Print the problem hierarchy.
print(problem.show())
```
Output:
```
+Example Problem
+--Criteria_1
+----Alternative_1
+----Alternative_2
+--Criteria_2
+----Alternative_1
+----Alternative_2
```
### Models
AnaHiePro has two types of models that you can use to automatically solve the set problems: `Model` and `VaryDepthModel`.
#### Differences between `Model` and `VaryDepthModel`
These two classes are designed to solve different types of problems. Specifically, `VaryDepthModel` is used for problems with varying depths, as shown in the image below.

On the other hand, `Model` can solve problems that have a hierarchy with the same depth for each child, as illustrated in the next picture.

#### About Models
Each model class in AnaHiePro has methods that are described below.
| Method Name | Description |
|-------------------|---------------------------------------------------|
| `__init__(self, problem: Problem, criterias, alternatives: list)` | Initialize the model with a problem, criteria, and alternatives. Also checks if the criterias has correct format, type and for `Model` - if the depth of the criterias hierarchy is the same depth. |
| `get_problem(self)` | Return the problem instance. |
| `get_alternatives(self)` | Return the list of alternatives. |
| `get_criterias_name_ids(self)` | Get the names and IDs of the criteria. |
| `find_criteria(self, key: tuple)` | Find criteria by (name, id) tuple. |
| `attach_criteria_pcm(self, key: tuple, pcm)`| Attach a pairwise comparison matrix to the criteria identified by the key. |
| `__getitem__(self, key: tuple)` | Get the criteria identified by the key. |
| `solve(self, showAlternatives=False)` | Solve the model to calculate the global priority vector. |
| `show(self)` | Display the problem. |
#### Examples
`Model` and `VaryDepthModel` can take the next format of the criterias in their `__init__` method:
```py
criterias = [Criteria(children=[Criteria()]),
Criteria(children=[Criteria()]),
Criteria(children=[Criteria()])]
```
or
```py
criterias = [
{Criteria(): [
{Criteria(): None}
]},
{Criteria(): [
{Criteria(): None}
]},
{Criteria(): [
{Criteria(): None}
]}
]
```
Another formats of the `criterias` param is not added (except of empty list).
Here you can see the simplest way how to create `Model` instance:
```py
from anahiepro.nodes import Problem, Criteria, Alternative
from anahiepro.models.model import Model
problem = Problem("Example Problem")
list_of_criterias = [
Criteria("Citeria_1", children=[
Criteria("Criteria_4")
]),
Criteria("Citeria_2", children=[
Criteria("Criteria_5")
]),
Criteria("Citeria_3", children=[
Criteria("Criteria_5")
]),
]
alternatives = [
Alternative("Alternative_1"),
Alternative("Alternative_2")
]
model = Model(problem, list_of_criterias, alternatives)
print(model.show())
```
Output:
```
+Example Problem
+--Citeria_1
+----Criteria_4
+------Alternative_1
+------Alternative_2
+--Citeria_2
+----Criteria_5
+------Alternative_1
+------Alternative_2
+--Citeria_3
+----Criteria_5
+------Alternative_1
+------Alternative_2
```
Now let's see how it works for `VaryDepthModel`:
```py
from anahiepro.nodes import Problem, Criteria, Alternative
from anahiepro.models.vary_depth_model import VaryDepthModel
problem = Problem("Example Problem")
list_of_criterias = [
Criteria("Citeria_1", children=[
Criteria("Criteria_4")
]),
Criteria("Citeria_2", children=[
Criteria("Criteria_5")
]),
Criteria("Citeria_3"), # <- Here Criteria_3 does not have children.
]
alternatives = [
Alternative("Alternative_1"),
Alternative("Alternative_2")
]
model = VaryDepthModel(problem, list_of_criterias, alternatives)
print(model.show())
```
Output:
```
+Example Problem
+--Citeria_1
+----Criteria_4
+------Alternative_1
+------Alternative_2
+--Citeria_2
+----Criteria_5
+------Alternative_1
+------Alternative_2
+--DummyCriteria0
+----Citeria_3
+------Alternative_1
+------Alternative_2
```
So, as you can see from the output, `VaryDepthModel` normalized the hierarchy. And, yes, you can use `VaryDepthModel` with the example for `Model` class.
#### Example with the solving of the hierarchy
```py
from anahiepro.nodes import Problem, Criteria, Alternative
from anahiepro.models.model import Model
problem = Problem("Example Problem", pcm=[[1, 2, 1/2],
[1/2, 1, 1/7],
[2, 7, 1]])
list_of_criterias = [
Criteria("Citeria_1", pcm=[[1, 2, 4],
[1/2, 1, 3],
[1/4, 1/3, 1]]),
Criteria("Citeria_2", pcm=[[1, 2, 1/5],
[1/2, 1, 3],
[5, 1/3, 1]]),
Criteria("Citeria_3", pcm=[[1, 1/3, 3],
[3, 1, 3],
[1/3, 1/3, 1]]),
]
alternatives = [
Alternative("Alternative_1"),
Alternative("Alternative_2"),
Alternative("Alternative_3")
]
model = Model(problem, list_of_criterias, alternatives)
print("Global vector without alternatives:")
print(model.solve())
print("Global vector with alternatives:")
print(model.solve(showAlternatives=True))
```
Output:
```
Global vector without alternatives:
[0.64557092 0.88998852 0.15336415]
Global vector with alternatives:
[(Alternative_1, np.float64(0.6455709201621959)), (Alternative_2, np.float64(0.8899885172373624)), (Alternative_3, np.float64(0.15336414859759606))]
```
## ✍️ Authors <a name = "authors"></a>
- [@danylevych](https://github.com/danylevych) - Idea & Initial work
Raw data
{
"_id": null,
"home_page": "https://github.com/danylevych/AnaHiePro",
"name": "AnaHiePro",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Oleh Danylevych",
"author_email": "danylevych123@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4d/24/c95034b772aff298d6d957c032108d6a3ce3d24c95dc5f43071ed8c8f8dc/anahiepro-0.0.0.1.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <a href=\"\" rel=\"noopener\">\n <img width=400px src=\"assets/img/title.png\" alt=\"Project logo\"></a>\n</p>\n\n<h1 align=\"center\">AnaHiePro</h1>\n\n<div align=\"center\">\n\n[]()\n[](https://github.com/danylevych/AnaHiePro/issues)\n[](https://github.com/danylevych/AnaHiePro/pulls)\n[](/LICENSE)\n\n</div>\n\n---\n\n<p> \n<b>AnaHiePro</b> is a module that allows solving various tasks of systems analysis using the Analytic Hierarchy Process (AHP).\n <br> \n</p>\n\n## \ud83d\udcdd Content\n\n- [About](#about)\n- [Getting Started](#getting_started)\n- [Usage](#usage)\n- [Authors](#authors)\n\n\n## \ud83e\uddd0 About <a name = \"about\"></a>\n\n<b>AnaHiePro</b> is a Python module designed to simplify the decision-making process by using the Analytic Hierarchy Process (AHP) method. This method allows you to structure complex problems in the form of a hierarchical model consisting of goals, criteria, and alternatives. AnaHiePro automatically calculates global priorities for the entire hierarchy.\n\nThe module provides a recursive traversal of the hierarchical tree, starting from the leaf nodes and moving up to the root. Each level of the hierarchy is processed by multiplying the matrix of local child vectors by the global parent vector, which allows you to determine the weight of each element at all levels. This makes AnaHiePro an ideal tool for analyzing complex systems and making informed decisions in a variety of fields, including business, project management, scientific research, and more.\n\n## \ud83c\udfc1 Getting Started <a name=\"getting_started\"></a>\n\n<h4>These are simple instructions on how to install <b>AnaHiePro</b> on your PC and start using it.</h4>\n\n### Installing\n\nOpen the terminal window (Linux and macOS) or command line (Windows). Then use the `pip` command to install the module:\n\n```sh\npip install anahiepro\n```\n\n### Prerequisites\n\nBefore installing AnaHiePro, ensure you have Python 3.x and `pip` installed on your system. You can download the latest version of Python from [python.org](https://www.python.org/).\n\nAfter loading you can use all AnaHiePro's functionality, down below you can see the simplest way of using AnaHiePro.\n\n```py\nfrom anahiepro.nodes import Problem, Criteria, Alternative\nfrom anahiepro.models.model import Model\n\nproblem = Problem(\"Example Problem\")\n\nlist_of_criterias = [\n Criteria(\"Citeria_1\"),\n Criteria(\"Citeria_2\"),\n Criteria(\"Citeria_3\")\n]\n\nalternatives = [\n Alternative(\"Alternative_1\"),\n Alternative(\"Alternative_2\")\n]\n\nmodel = Model(problem, list_of_criterias, alternatives)\n\nprint(model.show())\n```\n\n\n## \ud83c\udf88 Usage <a name=\"usage\"></a>\n\n- [Pairwise comparison matrix](#pairwise_matrix)\n- [Nodes](#nodes)\n- [Models](#models)\n- [Tools](#tools)\n\n\n### Pairwise matrix <a name=\"pairwise_matrix\"></a>\n\n`PairwiseComparisonMatrix` represents the pairwise comparison matrix. A pairwise comparison matrix is a tool used in decision-making processes. It helps compare different options or criteria by evaluating them in pairs. Each element of the matrix represents the comparison result between two options or criteria.\n\n#### Methods\n\n\n| Method Name | Description |\n|-------------------|---------------------------------------------------|\n| `__init__(self, size, matrix)` | Initialize a pairwise comparison matrix with the given size or given matrix. |\n| `set_comparison(self, i, j, value)` | Set the comparison value for the given indices. Might raise the `ValueError` exception when you try to set diagonal values to value, that not equal `1`. | \n| `set_matrix(self, matrix)` | Set the entire matrix, ensuring it is a valid pairwise comparison matrix. Might raise the `ValueError` if the matrix is not consistent or not valid.|\n| `get_matrix(self)` | Returns the current pairwise comparison matrix. |\n| `calculate_priority_vector(self)` | Calculate the priority vector from the pairwise comparison matrix. |\n| `calculate_consistency_ratio(self)` | Calculate the consistency ratio of the pairwise comparison matrix. |\n| `__getitem__(self, key)` | Returns the value at the specified index in the matrix. |\n| `__setitem__(self, key, value)` | Set the value at the specified index in the matrix. |\n\n#### Example\n\n```py\nfrom anahiepro.pairwise import PairwiseComparisonMatrix\n\n\nmatrix = [\n [1, 2, 3],\n [1/2, 1, 2],\n [1/3, 1/2, 1] \n]\n\npairwise_matrix = PairwiseComparisonMatrix(matrix=matrix)\n\nprint(pairwise_matrix.get_matrix())\nprint(\"Consistency ratio:\", pairwise_matrix.calculate_consistency_ratio())\nprint(\"Priority vector:\", pairwise_matrix.calculate_priority_vector())\n```\n\nOutput:\n```\n[[1. 2. 3. ]\n [0.5 1. 2. ]\n [0.33333333 0.5 1. ]]\nConsistency ratio: 0.007933373029552656\nPriority vector: [0.84679693 0.46601031 0.25645536]\n```\n\n### Nodes\n\nAnaHiePro has three types of nodes: Problem, Criteria (also DummyCriteria, which use for normalizing the model) and Alternative. All of them is inherited from abstract class `Node`. \n\n> **_NOTE:_** And we want to mentione that each class which is inhereted from `Node` has an id field.\n\n#### Node class\n\nAs we mentioned before, `Node` is a basic class for `Problem`, `Criteria` and `Alternative`. Down below you can see all `Node`'s methods:\n<br>\n\n| Method Name | Description |\n|-------------------|---------------------------------------------------|\n| `__init__(self, name, parents, children, id, pcm)` | Initialize the `Node` object with given `name`, list of its `parents`, list of `children`, identifier (`id`) and pcm. |\n| `get_name(self)` | Returns the name of the node. |\n| `get_parents(self)` | Returns list of parents for the node. |\n| `get_children(self)` | Returns list of children for the node. |\n| `get_key(self)` | Returns the tuple object, which consists of name of a node and its id. |\n| `add_child(self, child)` | Add `child` to the list of children. |\n| `show(self)` | Returns str object, which represent all relations between nodes. |\n| `compare(self, key: tuple)` | Compare the node with a given key, where `key` is a tuple object which has size that equal 2. `key[0]` is a name of node and `key[1]` is an identifier of the node. |\n| `create_pcm(self)` | Create a pairwise comparison matrix (PCM) object for the node which shape is equal number of node's childrens. |\n| `set_matrix(self, matrix)` | Attach given PCM to the node. If the `self.pcm` does not exist call the `create_pcm` method than checks if the shape of given matrix matchs, raise `VlalueError` if does not otherwise attach it. |\n| `set_comparison(self, i, j, value)` | Set given `value` to the right place. Other words it is a wrapper above the `PairwiseComparisonMatrix`'s `set_comparison` method. |\n| `get_priority_vector(self)` | Wrapper above PairwiseComparisonMatrix`'s `get_priority_vector` method. |\n| `get_consistency_ratio(self)` | Wrapper above PairwiseComparisonMatrix`'s `get_consistency_ratio` method. |\n| `get_pcm(self)` | Returns the pairwise comparison matrix of the node. |\n| `__eq__(self, value)` | Compare two `Node`'s instance. |\n| `def show(self)` | Show the node and its children in a hierarchical structure. |\n| `__copy__(self)` | Copy the node. |\n\n\n#### Problem class\n\n`Problem` is a class that represents the problem that the user wants to solve. This class inherits from Node and has the same methods as its parent. However, it overrides some methods.\n\n| Method Name | Description |\n|-------------------|---------------------------------------------------|\n| `__init__(self, name, children, pcm)` | Initialize the `Problem` object with given `name`, list of its childern and pairwise comparison matrix. |\n\nThe remaining methods are the same as in the `Node` class.\n\n#### Criteria class \n\n`Criteria` represents the criteria which will be used for selection. This class inherits form `Node` and has the same methods as his parrent, except of this it overrides some methods.\n\n| Method Name | Description |\n|-------------------|---------------------------------------------------|\n| `__init__(self, name, children, pcm)` | Initialize the `Criteria` object with given `name`, list of its childern and pairwise comparison matrix. |\n\nThe remaining methods are the same as in the `Node` class.\n\n#### DummyCriteria class\n\n`DummyCriteria` class that inherited from `Criteria` it is used for normalizing problem in `VaryDepthModel`.\n\n#### Alternative class\n\n`Alternative` represents alternatives between which the selection occurs. Since `Alternative` is the final node in the hierarchy, it has no children, so the self.pcm field for it is deleted.\n\n| Method Name | Description |\n|-------------------|---------------------------------------------------|\n| `__init__(self, name)` | Initialize the `Alternative` object with given `name`. |\n| `create_pcm(self)` | Not implemented for reasons which were mentioned. |\n| `set_matrix(self, matrix)` | Not implemented and raise `NotImplementedError` exception. |\n| `set_comparison(self, i, j, value) | Not implemented and raise `NotImplementedError` exception. |\n\nThe remaining methods are the same as in the `Node` class.\n\n#### Example\n\n```py\nfrom anahiepro.nodes import Problem, Criteria, Alternative\n\n\n# Create instance of each classes.\nproblem = Problem(\"Example Problem\")\n\ncriteria1 = Criteria(\"Criteria_1\")\ncriteria2 = Criteria(\"Criteria_2\")\n\nalternative1 = Alternative(\"Alternative_1\")\nalternative2 = Alternative(\"Alternative_2\")\n\n# Linking each instances.\nproblem.add_child(criteria1)\nproblem.add_child(criteria2)\n\ncriteria1.add_child(alternative1)\ncriteria1.add_child(alternative2)\n\ncriteria2.add_child(alternative1)\ncriteria2.add_child(alternative2)\n\n# Print the problem hierarchy.\nprint(problem.show())\n```\n\nOutput:\n\n```\n+Example Problem\n+--Criteria_1\n+----Alternative_1\n+----Alternative_2\n+--Criteria_2\n+----Alternative_1\n+----Alternative_2\n```\n\n### Models\n\nAnaHiePro has two types of models that you can use to automatically solve the set problems: `Model` and `VaryDepthModel`.\n\n#### Differences between `Model` and `VaryDepthModel`\n\nThese two classes are designed to solve different types of problems. Specifically, `VaryDepthModel` is used for problems with varying depths, as shown in the image below.\n\n\n\nOn the other hand, `Model` can solve problems that have a hierarchy with the same depth for each child, as illustrated in the next picture.\n\n\n\n#### About Models\n\nEach model class in AnaHiePro has methods that are described below.\n\n| Method Name | Description |\n|-------------------|---------------------------------------------------|\n| `__init__(self, problem: Problem, criterias, alternatives: list)` | Initialize the model with a problem, criteria, and alternatives. Also checks if the criterias has correct format, type and for `Model` - if the depth of the criterias hierarchy is the same depth. |\n| `get_problem(self)` | Return the problem instance. |\n| `get_alternatives(self)` | Return the list of alternatives. |\n| `get_criterias_name_ids(self)` | Get the names and IDs of the criteria. |\n| `find_criteria(self, key: tuple)` | Find criteria by (name, id) tuple. |\n| `attach_criteria_pcm(self, key: tuple, pcm)`| Attach a pairwise comparison matrix to the criteria identified by the key. |\n| `__getitem__(self, key: tuple)` | Get the criteria identified by the key. |\n| `solve(self, showAlternatives=False)` | Solve the model to calculate the global priority vector. |\n| `show(self)` | Display the problem. | \n\n#### Examples\n\n`Model` and `VaryDepthModel` can take the next format of the criterias in their `__init__` method:\n\n```py\ncriterias = [Criteria(children=[Criteria()]), \n Criteria(children=[Criteria()]),\n Criteria(children=[Criteria()])]\n```\n\nor \n\n```py\ncriterias = [\n {Criteria(): [\n {Criteria(): None}\n ]},\n {Criteria(): [\n {Criteria(): None}\n ]},\n {Criteria(): [\n {Criteria(): None}\n ]}\n]\n```\n\n\nAnother formats of the `criterias` param is not added (except of empty list).\n\nHere you can see the simplest way how to create `Model` instance:\n\n```py\nfrom anahiepro.nodes import Problem, Criteria, Alternative\nfrom anahiepro.models.model import Model\n\nproblem = Problem(\"Example Problem\")\n\nlist_of_criterias = [\n Criteria(\"Citeria_1\", children=[\n Criteria(\"Criteria_4\")\n ]),\n Criteria(\"Citeria_2\", children=[\n Criteria(\"Criteria_5\")\n ]),\n Criteria(\"Citeria_3\", children=[\n Criteria(\"Criteria_5\")\n ]),\n]\n\nalternatives = [\n Alternative(\"Alternative_1\"),\n Alternative(\"Alternative_2\")\n]\n\nmodel = Model(problem, list_of_criterias, alternatives)\n\nprint(model.show())\n```\n\nOutput:\n\n```\n+Example Problem\n+--Citeria_1\n+----Criteria_4\n+------Alternative_1\n+------Alternative_2\n+--Citeria_2\n+----Criteria_5\n+------Alternative_1\n+------Alternative_2\n+--Citeria_3\n+----Criteria_5\n+------Alternative_1\n+------Alternative_2\n```\n\nNow let's see how it works for `VaryDepthModel`:\n\n```py\nfrom anahiepro.nodes import Problem, Criteria, Alternative\nfrom anahiepro.models.vary_depth_model import VaryDepthModel\n\nproblem = Problem(\"Example Problem\")\n\nlist_of_criterias = [\n Criteria(\"Citeria_1\", children=[\n Criteria(\"Criteria_4\")\n ]),\n Criteria(\"Citeria_2\", children=[\n Criteria(\"Criteria_5\")\n ]),\n Criteria(\"Citeria_3\"), # <- Here Criteria_3 does not have children.\n]\n\nalternatives = [\n Alternative(\"Alternative_1\"),\n Alternative(\"Alternative_2\")\n]\n\nmodel = VaryDepthModel(problem, list_of_criterias, alternatives)\n\nprint(model.show())\n```\n\nOutput:\n\n```\n+Example Problem\n+--Citeria_1\n+----Criteria_4\n+------Alternative_1\n+------Alternative_2\n+--Citeria_2\n+----Criteria_5\n+------Alternative_1\n+------Alternative_2\n+--DummyCriteria0\n+----Citeria_3\n+------Alternative_1\n+------Alternative_2\n```\n\nSo, as you can see from the output, `VaryDepthModel` normalized the hierarchy. And, yes, you can use `VaryDepthModel` with the example for `Model` class.\n\n#### Example with the solving of the hierarchy\n\n```py\nfrom anahiepro.nodes import Problem, Criteria, Alternative\nfrom anahiepro.models.model import Model\n\nproblem = Problem(\"Example Problem\", pcm=[[1, 2, 1/2],\n [1/2, 1, 1/7],\n [2, 7, 1]])\n\nlist_of_criterias = [\n Criteria(\"Citeria_1\", pcm=[[1, 2, 4],\n [1/2, 1, 3],\n [1/4, 1/3, 1]]),\n \n Criteria(\"Citeria_2\", pcm=[[1, 2, 1/5],\n [1/2, 1, 3],\n [5, 1/3, 1]]),\n \n Criteria(\"Citeria_3\", pcm=[[1, 1/3, 3],\n [3, 1, 3],\n [1/3, 1/3, 1]]),\n]\n\nalternatives = [\n Alternative(\"Alternative_1\"),\n Alternative(\"Alternative_2\"),\n Alternative(\"Alternative_3\")\n]\n\nmodel = Model(problem, list_of_criterias, alternatives)\n\nprint(\"Global vector without alternatives:\")\nprint(model.solve())\n\nprint(\"Global vector with alternatives:\")\nprint(model.solve(showAlternatives=True))\n```\n\nOutput:\n```\nGlobal vector without alternatives:\n[0.64557092 0.88998852 0.15336415]\n\nGlobal vector with alternatives:\n[(Alternative_1, np.float64(0.6455709201621959)), (Alternative_2, np.float64(0.8899885172373624)), (Alternative_3, np.float64(0.15336414859759606))]\n```\n\n## \u270d\ufe0f Authors <a name = \"authors\"></a>\n\n- [@danylevych](https://github.com/danylevych) - Idea & Initial work\n",
"bugtrack_url": null,
"license": null,
"summary": "\"AnaHiePro\" is a module that allows solving various tasks of systems analysis using the Analytic Hierarchy Process (AHP).",
"version": "0.0.0.1",
"project_urls": {
"Homepage": "https://github.com/danylevych/AnaHiePro"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b7f4a96958d61076b8099edfe10248a37fb19aebd9a08ddf1ebda9ff835181ce",
"md5": "4a37ca9777cfd1394e13a0878601f9d5",
"sha256": "013292a6aa7d98ee98d9eb2bb91123a459e9d148fd9657cc0e0fa82decf82dcd"
},
"downloads": -1,
"filename": "AnaHiePro-0.0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4a37ca9777cfd1394e13a0878601f9d5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 17603,
"upload_time": "2024-07-13T19:09:15",
"upload_time_iso_8601": "2024-07-13T19:09:15.081536Z",
"url": "https://files.pythonhosted.org/packages/b7/f4/a96958d61076b8099edfe10248a37fb19aebd9a08ddf1ebda9ff835181ce/AnaHiePro-0.0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4d24c95034b772aff298d6d957c032108d6a3ce3d24c95dc5f43071ed8c8f8dc",
"md5": "c13522bfd3237dba3dac8f2e8bd16b97",
"sha256": "a3d7d20369fadd5f2175bc3680f164e22ed0625b0679a9b34f262cd678af5e60"
},
"downloads": -1,
"filename": "anahiepro-0.0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "c13522bfd3237dba3dac8f2e8bd16b97",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 133442,
"upload_time": "2024-07-13T19:09:17",
"upload_time_iso_8601": "2024-07-13T19:09:17.646689Z",
"url": "https://files.pythonhosted.org/packages/4d/24/c95034b772aff298d6d957c032108d6a3ce3d24c95dc5f43071ed8c8f8dc/anahiepro-0.0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-13 19:09:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "danylevych",
"github_project": "AnaHiePro",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "anahiepro"
}