-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Run all the example files and convert them to markdown files containing the output. | ||
Uses `pweave`. | ||
""" | ||
|
||
import pweave, datetime, glob, os | ||
|
||
|
||
def publish_to_markdown(python_file: str, output_file: str): | ||
doc = pweave.Pweb(python_file, kernel="python3", doctype="markdown", output=output_file) | ||
|
||
doc.theme = "skeleton" # The default option is skeleton , other options are pweave (the old theme), bootstrap , cerulean and journal. All look the same to me. | ||
|
||
doc.read() | ||
doc.run() | ||
doc.format() | ||
doc.formatted += f"\n---\nMarkdown generated automatically from [{python_file}]({python_file}) using [Pweave](http://mpastell.com/pweave) {pweave.__version__} on {datetime.date.today()}.\n" | ||
doc.write() | ||
|
||
|
||
if __name__ == "__main__": | ||
for python_file in glob.glob("*.py"): | ||
print(python_file) | ||
if python_file != os.path.basename(__file__): | ||
output_file = python_file.replace(".py", ".md") | ||
publish_to_markdown(python_file, output_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Input formats | ||
|
||
|
||
```python | ||
import fairpyx | ||
divide = fairpyx.divide | ||
``` | ||
|
||
|
||
|
||
`fairpyx` allows various input formats, so that you can easily use it on your own data, | ||
whether for applications or for research. | ||
For example, suppose you want to divide candies among your children. | ||
It is convenient to collect their preferences in a dict of dicts: | ||
|
||
|
||
```python | ||
valuations = { | ||
"Ami": {"green": 8, "red":7, "blue": 6, "yellow": 5}, | ||
"Tami": {"green": 12, "red":8, "blue": 4, "yellow": 2} } | ||
allocation = divide(fairpyx.algorithms.round_robin, valuations=valuations) | ||
``` | ||
|
||
|
||
|
||
You can then see the resulting allocation with the agents' real names: | ||
|
||
|
||
```python | ||
print(allocation) | ||
``` | ||
|
||
``` | ||
{'Ami': ['blue', 'green'], 'Tami': ['red', 'yellow']} | ||
``` | ||
|
||
|
||
|
||
For research, passing a dict of dicts as a parameter may be too verbose. | ||
You can call the same algorithm with only the values, or only the value matrix: | ||
|
||
|
||
```python | ||
print(divide(fairpyx.algorithms.round_robin, valuations={"Ami": [8,7,6,5], "Tami": [12,8,4,2]})) | ||
print(divide(fairpyx.algorithms.round_robin, valuations=[[8,7,6,5], [12,8,4,2]])) | ||
|
||
|
||
# #' For experiments, you can use a numpy random matrix: | ||
|
||
import numpy as np | ||
valuations = np.random.randint(1,100,[2,4]) | ||
print(valuations) | ||
allocation = divide(fairpyx.algorithms.round_robin, valuations=valuations) | ||
print(allocation) | ||
``` | ||
|
||
``` | ||
{'Ami': [0, 2], 'Tami': [1, 3]} | ||
{0: [0, 2], 1: [1, 3]} | ||
[[70 26 35 78] | ||
[47 8 51 38]] | ||
{0: [0, 3], 1: [1, 2]} | ||
``` | ||
|
||
|
||
--- | ||
Markdown generated automatically from [input_formats.py](input_formats.py) using [Pweave](http://mpastell.com/pweave) 0.30.3 on 2023-10-18. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#' # Input formats | ||
|
||
import fairpyx | ||
divide = fairpyx.divide | ||
|
||
#' `fairpyx` allows various input formats, so that you can easily use it on your own data, | ||
#' whether for applications or for research. | ||
#' For example, suppose you want to divide candies among your children. | ||
#' It is convenient to collect their preferences in a dict of dicts: | ||
|
||
valuations = { | ||
"Ami": {"green": 8, "red":7, "blue": 6, "yellow": 5}, | ||
"Tami": {"green": 12, "red":8, "blue": 4, "yellow": 2} } | ||
allocation = divide(fairpyx.algorithms.round_robin, valuations=valuations) | ||
|
||
#' You can then see the resulting allocation with the agents' real names: | ||
|
||
print(allocation) | ||
|
||
#' For research, passing a dict of dicts as a parameter may be too verbose. | ||
#' You can call the same algorithm with only the values, or only the value matrix: | ||
|
||
print(divide(fairpyx.algorithms.round_robin, valuations={"Ami": [8,7,6,5], "Tami": [12,8,4,2]})) | ||
print(divide(fairpyx.algorithms.round_robin, valuations=[[8,7,6,5], [12,8,4,2]])) | ||
|
||
|
||
# #' For experiments, you can use a numpy random matrix: | ||
|
||
import numpy as np | ||
valuations = np.random.randint(1,100,[2,4]) | ||
print(valuations) | ||
allocation = divide(fairpyx.algorithms.round_robin, valuations=valuations) | ||
print(allocation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from fairpyx.algorithms.picking_sequence import round_robin, bidirectional_round_robin, serial_dictatorship |