Skip to content

Commit 3622e94

Browse files
MaximSmolskiypre-commit-ci[bot]
andauthoredDec 29, 2024··
Fix sphinx/build_docs warnings for other (#12482)
* Fix sphinx/build_docs warnings for other * Fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ce036db commit 3622e94

File tree

3 files changed

+77
-63
lines changed

3 files changed

+77
-63
lines changed
 

‎other/bankers_algorithm.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
predetermined maximum possible amounts of all resources, and then makes a "s-state"
1111
check to test for possible deadlock conditions for all other pending activities,
1212
before deciding whether allocation should be allowed to continue.
13-
[Source] Wikipedia
14-
[Credit] Rosetta Code C implementation helped very much.
15-
(https://rosettacode.org/wiki/Banker%27s_algorithm)
13+
14+
| [Source] Wikipedia
15+
| [Credit] Rosetta Code C implementation helped very much.
16+
| (https://rosettacode.org/wiki/Banker%27s_algorithm)
1617
"""
1718

1819
from __future__ import annotations
@@ -75,7 +76,7 @@ def __available_resources(self) -> list[int]:
7576
def __need(self) -> list[list[int]]:
7677
"""
7778
Implement safety checker that calculates the needs by ensuring that
78-
max_claim[i][j] - alloc_table[i][j] <= avail[j]
79+
``max_claim[i][j] - alloc_table[i][j] <= avail[j]``
7980
"""
8081
return [
8182
list(np.array(self.__maximum_claim_table[i]) - np.array(allocated_resource))
@@ -86,7 +87,9 @@ def __need_index_manager(self) -> dict[int, list[int]]:
8687
"""
8788
This function builds an index control dictionary to track original ids/indices
8889
of processes when altered during execution of method "main"
89-
Return: {0: [a: int, b: int], 1: [c: int, d: int]}
90+
91+
:Return: {0: [a: int, b: int], 1: [c: int, d: int]}
92+
9093
>>> index_control = BankersAlgorithm(
9194
... test_claim_vector, test_allocated_res_table, test_maximum_claim_table
9295
... )._BankersAlgorithm__need_index_manager()
@@ -100,7 +103,8 @@ def __need_index_manager(self) -> dict[int, list[int]]:
100103
def main(self, **kwargs) -> None:
101104
"""
102105
Utilize various methods in this class to simulate the Banker's algorithm
103-
Return: None
106+
:Return: None
107+
104108
>>> BankersAlgorithm(test_claim_vector, test_allocated_res_table,
105109
... test_maximum_claim_table).main(describe=True)
106110
Allocated Resource Table

‎other/davis_putnam_logemann_loveland.py

+51-43
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
class Clause:
1919
"""
20-
A clause represented in Conjunctive Normal Form.
21-
A clause is a set of literals, either complemented or otherwise.
20+
| A clause represented in Conjunctive Normal Form.
21+
| A clause is a set of literals, either complemented or otherwise.
22+
2223
For example:
23-
{A1, A2, A3'} is the clause (A1 v A2 v A3')
24-
{A5', A2', A1} is the clause (A5' v A2' v A1)
24+
* {A1, A2, A3'} is the clause (A1 v A2 v A3')
25+
* {A5', A2', A1} is the clause (A5' v A2' v A1)
2526
2627
Create model
28+
2729
>>> clause = Clause(["A1", "A2'", "A3"])
2830
>>> clause.evaluate({"A1": True})
2931
True
@@ -39,6 +41,7 @@ def __init__(self, literals: list[str]) -> None:
3941
def __str__(self) -> str:
4042
"""
4143
To print a clause as in Conjunctive Normal Form.
44+
4245
>>> str(Clause(["A1", "A2'", "A3"]))
4346
"{A1 , A2' , A3}"
4447
"""
@@ -47,6 +50,7 @@ def __str__(self) -> str:
4750
def __len__(self) -> int:
4851
"""
4952
To print a clause as in Conjunctive Normal Form.
53+
5054
>>> len(Clause([]))
5155
0
5256
>>> len(Clause(["A1", "A2'", "A3"]))
@@ -72,11 +76,13 @@ def assign(self, model: dict[str, bool | None]) -> None:
7276
def evaluate(self, model: dict[str, bool | None]) -> bool | None:
7377
"""
7478
Evaluates the clause with the assignments in model.
79+
7580
This has the following steps:
76-
1. Return True if both a literal and its complement exist in the clause.
77-
2. Return True if a single literal has the assignment True.
78-
3. Return None(unable to complete evaluation) if a literal has no assignment.
79-
4. Compute disjunction of all values assigned in clause.
81+
1. Return ``True`` if both a literal and its complement exist in the clause.
82+
2. Return ``True`` if a single literal has the assignment ``True``.
83+
3. Return ``None`` (unable to complete evaluation)
84+
if a literal has no assignment.
85+
4. Compute disjunction of all values assigned in clause.
8086
"""
8187
for literal in self.literals:
8288
symbol = literal.rstrip("'") if literal.endswith("'") else literal + "'"
@@ -92,10 +98,10 @@ def evaluate(self, model: dict[str, bool | None]) -> bool | None:
9298

9399
class Formula:
94100
"""
95-
A formula represented in Conjunctive Normal Form.
96-
A formula is a set of clauses.
97-
For example,
98-
{{A1, A2, A3'}, {A5', A2', A1}} is ((A1 v A2 v A3') and (A5' v A2' v A1))
101+
| A formula represented in Conjunctive Normal Form.
102+
| A formula is a set of clauses.
103+
| For example,
104+
| {{A1, A2, A3'}, {A5', A2', A1}} is ((A1 v A2 v A3') and (A5' v A2' v A1))
99105
"""
100106

101107
def __init__(self, clauses: Iterable[Clause]) -> None:
@@ -107,16 +113,17 @@ def __init__(self, clauses: Iterable[Clause]) -> None:
107113
def __str__(self) -> str:
108114
"""
109115
To print a formula as in Conjunctive Normal Form.
110-
str(Formula([Clause(["A1", "A2'", "A3"]), Clause(["A5'", "A2'", "A1"])]))
116+
117+
>>> str(Formula([Clause(["A1", "A2'", "A3"]), Clause(["A5'", "A2'", "A1"])]))
111118
"{{A1 , A2' , A3} , {A5' , A2' , A1}}"
112119
"""
113120
return "{" + " , ".join(str(clause) for clause in self.clauses) + "}"
114121

115122

116123
def generate_clause() -> Clause:
117124
"""
118-
Randomly generate a clause.
119-
All literals have the name Ax, where x is an integer from 1 to 5.
125+
| Randomly generate a clause.
126+
| All literals have the name Ax, where x is an integer from ``1`` to ``5``.
120127
"""
121128
literals = []
122129
no_of_literals = random.randint(1, 5)
@@ -149,11 +156,12 @@ def generate_formula() -> Formula:
149156

150157
def generate_parameters(formula: Formula) -> tuple[list[Clause], list[str]]:
151158
"""
152-
Return the clauses and symbols from a formula.
153-
A symbol is the uncomplemented form of a literal.
159+
| Return the clauses and symbols from a formula.
160+
| A symbol is the uncomplemented form of a literal.
161+
154162
For example,
155-
Symbol of A3 is A3.
156-
Symbol of A5' is A5.
163+
* Symbol of A3 is A3.
164+
* Symbol of A5' is A5.
157165
158166
>>> formula = Formula([Clause(["A1", "A2'", "A3"]), Clause(["A5'", "A2'", "A1"])])
159167
>>> clauses, symbols = generate_parameters(formula)
@@ -177,21 +185,20 @@ def find_pure_symbols(
177185
clauses: list[Clause], symbols: list[str], model: dict[str, bool | None]
178186
) -> tuple[list[str], dict[str, bool | None]]:
179187
"""
180-
Return pure symbols and their values to satisfy clause.
181-
Pure symbols are symbols in a formula that exist only
182-
in one form, either complemented or otherwise.
183-
For example,
184-
{ { A4 , A3 , A5' , A1 , A3' } , { A4 } , { A3 } } has
185-
pure symbols A4, A5' and A1.
188+
| Return pure symbols and their values to satisfy clause.
189+
| Pure symbols are symbols in a formula that exist only in one form,
190+
| either complemented or otherwise.
191+
| For example,
192+
| {{A4 , A3 , A5' , A1 , A3'} , {A4} , {A3}} has pure symbols A4, A5' and A1.
193+
186194
This has the following steps:
187-
1. Ignore clauses that have already evaluated to be True.
188-
2. Find symbols that occur only in one form in the rest of the clauses.
189-
3. Assign value True or False depending on whether the symbols occurs
190-
in normal or complemented form respectively.
195+
1. Ignore clauses that have already evaluated to be ``True``.
196+
2. Find symbols that occur only in one form in the rest of the clauses.
197+
3. Assign value ``True`` or ``False`` depending on whether the symbols occurs
198+
in normal or complemented form respectively.
191199
192200
>>> formula = Formula([Clause(["A1", "A2'", "A3"]), Clause(["A5'", "A2'", "A1"])])
193201
>>> clauses, symbols = generate_parameters(formula)
194-
195202
>>> pure_symbols, values = find_pure_symbols(clauses, symbols, {})
196203
>>> pure_symbols
197204
['A1', 'A2', 'A3', 'A5']
@@ -231,20 +238,21 @@ def find_unit_clauses(
231238
) -> tuple[list[str], dict[str, bool | None]]:
232239
"""
233240
Returns the unit symbols and their values to satisfy clause.
241+
234242
Unit symbols are symbols in a formula that are:
235-
- Either the only symbol in a clause
236-
- Or all other literals in that clause have been assigned False
243+
- Either the only symbol in a clause
244+
- Or all other literals in that clause have been assigned ``False``
245+
237246
This has the following steps:
238-
1. Find symbols that are the only occurrences in a clause.
239-
2. Find symbols in a clause where all other literals are assigned False.
240-
3. Assign True or False depending on whether the symbols occurs in
241-
normal or complemented form respectively.
247+
1. Find symbols that are the only occurrences in a clause.
248+
2. Find symbols in a clause where all other literals are assigned ``False``.
249+
3. Assign ``True`` or ``False`` depending on whether the symbols occurs in
250+
normal or complemented form respectively.
242251
243252
>>> clause1 = Clause(["A4", "A3", "A5'", "A1", "A3'"])
244253
>>> clause2 = Clause(["A4"])
245254
>>> clause3 = Clause(["A3"])
246255
>>> clauses, symbols = generate_parameters(Formula([clause1, clause2, clause3]))
247-
248256
>>> unit_clauses, values = find_unit_clauses(clauses, {})
249257
>>> unit_clauses
250258
['A4', 'A3']
@@ -278,16 +286,16 @@ def dpll_algorithm(
278286
clauses: list[Clause], symbols: list[str], model: dict[str, bool | None]
279287
) -> tuple[bool | None, dict[str, bool | None] | None]:
280288
"""
281-
Returns the model if the formula is satisfiable, else None
289+
Returns the model if the formula is satisfiable, else ``None``
290+
282291
This has the following steps:
283-
1. If every clause in clauses is True, return True.
284-
2. If some clause in clauses is False, return False.
285-
3. Find pure symbols.
286-
4. Find unit symbols.
292+
1. If every clause in clauses is ``True``, return ``True``.
293+
2. If some clause in clauses is ``False``, return ``False``.
294+
3. Find pure symbols.
295+
4. Find unit symbols.
287296
288297
>>> formula = Formula([Clause(["A4", "A3", "A5'", "A1", "A3'"]), Clause(["A4"])])
289298
>>> clauses, symbols = generate_parameters(formula)
290-
291299
>>> soln, model = dpll_algorithm(clauses, symbols, {})
292300
>>> soln
293301
True

‎other/scoring_algorithm.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
"""
2-
developed by: markmelnic
3-
original repo: https://github.com/markmelnic/Scoring-Algorithm
2+
| developed by: markmelnic
3+
| original repo: https://github.com/markmelnic/Scoring-Algorithm
44
55
Analyse data using a range based percentual proximity algorithm
66
and calculate the linear maximum likelihood estimation.
77
The basic principle is that all values supplied will be broken
8-
down to a range from 0 to 1 and each column's score will be added
8+
down to a range from ``0`` to ``1`` and each column's score will be added
99
up to get the total score.
1010
11-
==========
1211
Example for data of vehicles
13-
price|mileage|registration_year
14-
20k |60k |2012
15-
22k |50k |2011
16-
23k |90k |2015
17-
16k |210k |2010
12+
::
13+
14+
price|mileage|registration_year
15+
20k |60k |2012
16+
22k |50k |2011
17+
23k |90k |2015
18+
16k |210k |2010
1819
1920
We want the vehicle with the lowest price,
2021
lowest mileage but newest registration year.
2122
Thus the weights for each column are as follows:
22-
[0, 0, 1]
23+
``[0, 0, 1]``
2324
"""
2425

2526

@@ -97,10 +98,11 @@ def procentual_proximity(
9798
source_data: list[list[float]], weights: list[int]
9899
) -> list[list[float]]:
99100
"""
100-
weights - int list
101-
possible values - 0 / 1
102-
0 if lower values have higher weight in the data set
103-
1 if higher values have higher weight in the data set
101+
| `weights` - ``int`` list
102+
| possible values - ``0`` / ``1``
103+
104+
* ``0`` if lower values have higher weight in the data set
105+
* ``1`` if higher values have higher weight in the data set
104106
105107
>>> procentual_proximity([[20, 60, 2012],[23, 90, 2015],[22, 50, 2011]], [0, 0, 1])
106108
[[20, 60, 2012, 2.0], [23, 90, 2015, 1.0], [22, 50, 2011, 1.3333333333333335]]

0 commit comments

Comments
 (0)
Please sign in to comment.