affect customer / remove customer up product conditionally
This commit is contained in:
parent
4b34dab443
commit
45a406961a
Binary file not shown.
9
firm.py
9
firm.py
|
@ -1,4 +1,5 @@
|
|||
import agentpy as ap
|
||||
import math
|
||||
|
||||
|
||||
class FirmAgent(ap.Agent):
|
||||
|
@ -29,7 +30,8 @@ class FirmAgent(ap.Agent):
|
|||
# remove edge
|
||||
# print(n1, n2, key, product_code)
|
||||
self.firm_network.graph.remove_edge(n1, n2, key)
|
||||
# remove customer up product if does not have alternative
|
||||
|
||||
# remove customer up product if does not have alternative / con
|
||||
customer = ap.AgentIter(self.model, n2).to_list()[0]
|
||||
list_in_edges = list(
|
||||
self.firm_network.graph.in_edges(n2,
|
||||
|
@ -40,7 +42,8 @@ class FirmAgent(ap.Agent):
|
|||
if edge[-1] == remove_product.code
|
||||
]
|
||||
# print(select_edges)
|
||||
if len(select_edges) == 0:
|
||||
p_remove = math.exp(-1 * len(select_edges))
|
||||
if self.model.nprandom.choice([True, False], p=[p_remove, 1-p_remove]):
|
||||
print(self.name, remove_product.code, 'affect', customer.name)
|
||||
if remove_product not in \
|
||||
customer.a_list_up_product_removed:
|
||||
|
@ -123,7 +126,7 @@ class FirmAgent(ap.Agent):
|
|||
# print(product.code, [firm.name for firm in list_firm])
|
||||
|
||||
def accept_request(self, down_firm, product):
|
||||
# if self.model.nprandom.choice([True, False], p=[0.1, 0.9]):
|
||||
if self.model.nprandom.choice([True, False], p=[0.1, 0.9]):
|
||||
self.firm_network.graph.add_edges_from([
|
||||
(self.firm_network.positions[self],
|
||||
self.firm_network.positions[down_firm], {
|
||||
|
|
31
test.ipynb
31
test.ipynb
|
@ -2,24 +2,35 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"85\n",
|
||||
"63\n",
|
||||
"51\n",
|
||||
"26\n",
|
||||
"30\n",
|
||||
"4\n",
|
||||
"7\n",
|
||||
"1\n",
|
||||
"17\n",
|
||||
"81\n"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"np.random.randint(0.5, 3.5)"
|
||||
"np.random.randint(0.5, 3.5)\n",
|
||||
"p_remove = 1\n",
|
||||
"np.random.choice([True, False], p=[p_remove, 1-p_remove])\n",
|
||||
"rng = np.random.default_rng(0)\n",
|
||||
"for _ in range(10):\n",
|
||||
" print(rng.integers(0,100))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -46,7 +57,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.8"
|
||||
"version": "3.9.13"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
|
|
Loading…
Reference in New Issue