Skip to content

Commit

Permalink
various corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfarouk committed Mar 22, 2019
1 parent 32118bf commit 39d9819
Show file tree
Hide file tree
Showing 30 changed files with 558 additions and 391 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -155,3 +155,4 @@ dask-worker-space/
*/out
*/py4j
pip-wheel-metadata

33 changes: 4 additions & 29 deletions docs/tutorials/06.run_scml.rst
Expand Up @@ -23,7 +23,7 @@ can set the number of steps to a small value (e.g. n\_steps=10).
.. code:: ipython3
world = SCMLWorld.single_path_world(agent_names_reveal_type=True
# n_steps=10 # remove this comment for a fast test but do not expect factories to gain anything
#, n_steps=10 # remove this comment for a fast test but do not expect factories to gain anything
)
For debugging purposes, we set ``agent_names_reveal_type`` to true to be
Expand All @@ -46,9 +46,7 @@ conducted over time
plt.ylabel('N. Negotiations')
plt.show()
.. image:: 06.run_scml_files/06.run_scml_7_0.png
:width: 1069px
:height: 386px
It is clear that many negotiations happened at the beginning of the
Expand Down Expand Up @@ -77,9 +75,7 @@ the total amount of money transferred due to trade)
plt.ylabel('Activitiy Level ($)\nTotal Money Transferred')
plt.show()
.. image:: 06.run_scml_files/06.run_scml_11_0.png
:width: 1069px
:height: 386px
We can see a picture of contracting in this world as follows:
Expand All @@ -96,10 +92,6 @@ We can see a picture of contracting in this world as follows:
plt.show()
.. image:: 06.run_scml_files/06.run_scml_13_0.png
:width: 1069px
:height: 386px

We can also check the breaches that happened
Expand All @@ -112,10 +104,6 @@ We can also check the breaches that happened
plt.show()
.. image:: 06.run_scml_files/06.run_scml_15_0.png
:width: 1069px
:height: 386px

It is also possible to focus on the behavior of some specific agent.
Expand All @@ -131,7 +119,7 @@ maximum wealth). Notice that there can be multiple winners
.. parsed-literal::
[greedy_1_0]
[greedy_1_4]
Expand All @@ -147,10 +135,6 @@ What was the balance of this winner over time:
plt.show()
.. image:: 06.run_scml_files/06.run_scml_19_0.png
:width: 1069px
:height: 386px

Let's check how did its total storage change over time:
Expand All @@ -165,10 +149,6 @@ Let's check how did its total storage change over time:
plt.show()
.. image:: 06.run_scml_files/06.run_scml_21_0.png
:width: 1069px
:height: 386px

We can actually check what happens to ALL competitors:
Expand All @@ -183,13 +163,8 @@ We can actually check what happens to ALL competitors:
plt.show()
.. image:: 06.run_scml_files/06.run_scml_23_0.png
:width: 1069px
:height: 386px

It is clear form the figure that the winner was by far the best player.
Download :download:`Notebook<notebooks/06.run_scml.ipynb>`.
Expand Down
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_11_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_11_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_13_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_13_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_15_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_15_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_19_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_19_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_21_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_21_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_23_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_23_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_7_0.pdf
Binary file not shown.
Binary file modified docs/tutorials/06.run_scml_files/06.run_scml_7_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 53 additions & 53 deletions docs/tutorials/notebooks/06.run_scml.ipynb

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions etc/06.run_scml.rst
Expand Up @@ -189,9 +189,6 @@ We can actually check what happens to ALL competitors:



It is clear form the figure that the winner was by far the best player.


Download :download:`Notebook<notebooks/06.run_scml.ipynb>`.


2 changes: 1 addition & 1 deletion negmas/apps/scml/__init__.py
Expand Up @@ -99,4 +99,4 @@
from . import helpers

__all__ = common.__all__ + awi.__all__ + factory_managers.__all__ + bank.__all__ + insurance.__all__ \
+ schedulers.__all__ + world.__all__ + consumers.__all__ + miners.__all__ + ['utils'] + ['helpers']
+ schedulers.__all__ + world.__all__ + consumers.__all__ + miners.__all__ + ['utils', 'helpers', 'java']
13 changes: 2 additions & 11 deletions negmas/apps/scml/awi.py
@@ -1,6 +1,6 @@
from py4j.java_collections import ListConverter

from negmas.java import JNegmasGateway, to_java, dict_encode, deep_dict_encode
from negmas.java import JNegmasGateway, to_dict, dict_encode, to_dict
from negmas.situated import AgentWorldInterface, Contract
from .common import *
from typing import Optional, List
Expand All @@ -11,14 +11,7 @@


class SCMLAWI(AgentWorldInterface):

def _allProducts(self) -> List[Product]:
products = deep_dict_encode(self.products)
return ListConverter().convert(products, JNegmasGateway.gateway._gateway_client)

def _allProcesses(self) -> List[Process]:
return self.processes

"""A single contact point between SCML agents and the world simulation."""
def register_cfp(self, cfp: CFP) -> None:
"""Registers a CFP"""
self._world.n_new_cfps += 1
Expand Down Expand Up @@ -67,6 +60,4 @@ def processes(self) -> List[Process]:
"""Processes in the world"""
return self._world.processes

class Java:
implements = ['jnegmas.apps.scml.awi.PySCMLAWI']

41 changes: 37 additions & 4 deletions negmas/apps/scml/common.py
Expand Up @@ -10,7 +10,7 @@
import numpy as np
from dataclasses import dataclass, field, InitVar

from negmas.java import JavaConvertible
from negmas.java import DictConvertible
from negmas.mechanisms import MechanismProxy
from negmas.negotiators import NegotiatorProxy
from negmas.outcomes import OutcomeType, Issue
Expand Down Expand Up @@ -421,7 +421,7 @@ class SCMLAgreement(OutcomeType):


@dataclass
class CFP(OutcomeType, JavaConvertible):
class CFP(OutcomeType):
"""A Call for proposal upon which a negotiation can start"""
is_buy: bool
"""If true, the author wants to buy otherwise to sell. Non-negotiable."""
Expand Down Expand Up @@ -702,8 +702,8 @@ def max_penalty(self):
class Java:
implements = ['jnegmas.apps.scml.PyCFP']

def to_java(self):
d = super().to_java()
def to_dict(self):
d = self.__dict__
d['min_time'], d['max_time'] = self.min_time, self.max_time
d['min_quantity'], d['max_quantity'] = self.min_quantity, self.max_quantity
d['min_unit_price'], d['max_unit_price'] = self.min_unit_price, self.max_unit_price
Expand All @@ -713,6 +713,39 @@ def to_java(self):
d['has_signing_delay'] = self.signing_delay is not None
d['has_money_resolution'] = self.money_resolution is not None
return d

@classmethod
def from_dict(cls, d: Dict[str, Any]) -> 'CFP':
if d['min_time'] == d['max_time']:
t = d['min_time']
else:
t = (d['min_time'], d['max_time'])
if d['min_quantity'] == d['max_quantity']:
q = d['min_quantity']
else:
q = (d['min_quantity'], d['max_quantity'])
if d['min_unit_price'] == d['max_unit_price']:
up = d['min_unit_price']
else:
up = (d['min_unit_price'], d['max_unit_price'])
if not d.get('min_penalty', None) or not p.get('max_penalty', None):
p = None
else:
if d['min_penalty'] == d['max_penalty']:
p = d['min_penalty']
else:
p = (d['min_penalty'], d['max_penalty'])
if not d.get('min_signing_delay', None) or not p.get('max_signing_delay', None):
s = None
else:
if d['min_signing_delay'] == d['max_signing_delay']:
s = d['min_signing_delay']
else:
s = (d['min_signing_delay'], d['max_signing_delay'])

return cls(is_buy=d['is_buy'], publisher=d['publisher'], product=d['product'], time=t, unit_price=up
, quantity=q, penalty=p, signing_delay=s, money_resolution=d.get('money_resolution', None)
, id=d.get('id', None))


@dataclass
Expand Down

0 comments on commit 39d9819

Please sign in to comment.