Skip to content
Snippets Groups Projects
Commit 86b6c9fb authored by Zizhe Wang's avatar Zizhe Wang
Browse files

Merge remote-tracking branch 'origin/master'

parents 9e46c6d7 c0ec63ff
No related branches found
No related tags found
No related merge requests found
<<<<<<< HEAD
model CarSharing
=======
model CarSharingSystem
// Parameters
parameter Integer numCars = 50 "Number of cars in the system";
parameter Integer numUsers = 50 "Number of users in the system";
// Discrete Places
>>>>>>> origin/master
PNlib.Components.PD PSCii(nIn = 1, nOut = 1) annotation(
Placement(transformation(origin = {-306, 90}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
PNlib.Components.TES TCRi(nIn = 1, nOut = 1) annotation(
Placement(transformation(origin = {-278, 54}, extent = {{-10, -10}, {10, 10}})));
PNlib.Components.PD PSRi(nIn = 1, nOut = 1) annotation(
Placement(transformation(origin = {-242, 82}, extent = {{-10, -10}, {10, 10}})));
<<<<<<< HEAD
PNlib.Components.PD PSCi(nIn = 1, nOut = 1, startTokens = 6) annotation(
Placement(transformation(origin = {-240, 116}, extent = {{10, -10}, {-10, 10}})));
PNlib.Components.T TUSi(nIn = 2, nOut = 2) annotation(
......@@ -12,6 +23,15 @@ model CarSharing
PNlib.Components.PD PCU(nIn = 3, nOut = 4, startTokens = 5) annotation(
Placement(transformation(origin = {26, 36}, extent = {{20, -20}, {-20, 20}}, rotation = -90)));
PNlib.Components.PD PSDi(nIn = 1, nOut = 2, startTokens = 1) annotation(
=======
PNlib.Components.PD PSCi(nIn = 1, nOut = 1, startTokens = numCars) annotation(
Placement(transformation(origin = {-240, 116}, extent = {{10, -10}, {-10, 10}})));
PNlib.Components.T TUSi(nIn = 2, nOut = 2) annotation(
Placement(transformation(origin = {-202, 82}, extent = {{-14, -14}, {14, 14}})));
PNlib.Components.PD PCU(nIn = 3, nOut = 4, startTokens = 0) annotation(
Placement(transformation(origin = {26, 36}, extent = {{20, -20}, {-20, 20}}, rotation = -90)));
PNlib.Components.PD PSDi(nIn = 1, nOut = 2, startTokens = numUsers) annotation(
>>>>>>> origin/master
Placement(transformation(origin = {-270, 10}, extent = {{-10, -10}, {10, 10}})));
PNlib.Components.TD TUNi(nIn = 1) annotation(
Placement(transformation(origin = {-180, 10}, extent = {{-10, -10}, {10, 10}})));
......@@ -136,4 +156,8 @@ equation
uses(PNlib(version = "3.0.0")),
Diagram(graphics = {Text(origin = {-337, -14}, extent = {{3, 0}, {-3, 0}}, textString = "text"), Text(origin = {-115, -90}, extent = {{3, 0}, {-3, 0}}, textString = "text"), Text(origin = {-304, 192}, extent = {{42, -20}, {-42, 0}}, textString = "Station subnet"), Rectangle(origin = {-245, 103}, lineColor = {0, 0, 255}, lineThickness = 0.5, extent = {{-103, 71}, {103, -71}}), Rectangle(origin = {-257, 5}, lineColor = {0, 255, 0}, lineThickness = 0.5, extent = {{-91, 23}, {91, -23}}), Text(origin = {-304, -20}, extent = {{42, -20}, {-42, 0}}, textString = "User demand subnet"), Rectangle(origin = {224, 30}, lineColor = {0, 170, 255}, lineThickness = 0.5, extent = {{-132, 72}, {132, -72}}), Text(origin = {121, 136}, extent = {{57, -48}, {-57, 0}}, textString = "User Demand (park) subnet"), Polygon(origin = {342, 55}, lineColor = {255, 85, 255}, lineThickness = 0.5, points = {{-154, 111}, {-154, 57}, {32, 57}, {32, -139}, {142, -139}, {142, 137}, {-154, 137}, {-154, 127}, {-154, 111}}), Text(origin = {273, 201}, extent = {{-81, 25}, {81, -25}}, textString = "Car Maintenance (Center) subnet"), Rectangle(origin = {293, -77}, lineColor = {85, 85, 0}, lineThickness = 0.5, extent = {{-145, 87}, {145, -87}}), Text(origin = {227, -176}, extent = {{-73, 20}, {73, -20}}, textString = "Car-Sharing Park (Center) subnet"), Text(extent = {{-16, 40}, {-16, 40}}, textString = "text"), Text(origin = {-20, 48}, extent = {{-26, 16}, {26, -16}}, textString = "Cars in use"), Text(origin = {-339, 67}, extent = {{-37, 35}, {37, -35}}, textString = "Charging of cars"), Text(origin = {-204, 63}, extent = {{-32, 7}, {32, -7}}, textString = "Cars are ready")}, coordinateSystem(extent = {{-380, 240}, {500, -200}})),
version = "");
<<<<<<< HEAD
end CarSharing;
=======
end CarSharingSystem;
>>>>>>> origin/master
model CarSharingSystemCaseStudy
// Parameters
parameter Integer numCars = 10 "Number of cars in the system";
parameter Integer numUsers = 1 "Number of users in the system";
parameter Real userArrivalRate = 1.0 "User arrival rate (users per time unit)";
parameter Real returnRate = 0.5 "Car return rate";
parameter Real chargingTime = 1.0 "Time to fully charge a car";
parameter Real usageTime = 1.0 "Car usage time by a customer";
parameter Real userPatience = 10.0 "Maximum waiting time for users";
// State variables for objectives
Real totalWaitingTime(start=0) "Total waiting time for users";
Real totalCarsRented(start=0) "Total number of cars rented";
discrete Integer usersLeaving(start=0);
// Discrete Place: Number of free places in the station
PNlib.Components.PD PSCii(nIn = 1, nOut = 1) annotation(
Placement(transformation(origin = {-306, 90}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
// Stochastic Transition: Car is ready and available for users after charging operation
PNlib.Components.TES TCRi(nIn = 1, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/chargingTime) annotation(
Placement(transformation(origin = {-278, 54}, extent = {{-10, -10}, {10, 10}})));
// Discrete Place: Cars parked at the station, ready and then available for users
PNlib.Components.PD PSRi(nIn = 1, nOut = 1, startTokens = numCars) annotation(
Placement(transformation(origin = {-242, 82}, extent = {{-10, -10}, {10, 10}})));
// Discrete Place: Number of free places in the station
PNlib.Components.PD PSCi(nIn = 1, nOut = 1, startTokens = 0) annotation(
Placement(transformation(origin = {-240, 116}, extent = {{10, -10}, {-10, 10}})));
// Immediate Transition: User demand "satisfied" and then "user departure" from station
PNlib.Components.T TUSi(nIn = 2, nOut = 2) annotation(
Placement(transformation(origin = {-202, 82}, extent = {{-14, -14}, {14, 14}})));
// Discrete Place: Car in use by customers
PNlib.Components.PD PCU(nIn = 2, nOut = 3, startTokens = 0) annotation(
Placement(transformation(origin = {1, 23}, extent = {{21, -21}, {-21, 21}}, rotation = -90)));
// Discrete Place: Users waiting -during a given random delay- for available and ready cars in the station
PNlib.Components.PD PSDi(nIn = 1, nOut = 2, startTokens = numUsers) annotation(
Placement(transformation(origin = {-270, 10}, extent = {{-10, -10}, {10, 10}})));
// Deterministic transition: User demand “not satisfied” at station
PNlib.Components.TD TUNi(nIn = 1, delay = userPatience) annotation(
Placement(transformation(origin = {-180, 10}, extent = {{-10, -10}, {10, 10}})));
// Stochastic Transition: User demand arrival at station
PNlib.Components.TES TUDi(nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/userArrivalRate) annotation(
Placement(transformation(origin = {-314, 10}, extent = {{-10, -10}, {10, 10}})));
// Stochastic Transition: Car return to station Si by user. Then, the car is in a charging situation
PNlib.Components.TES TCCi(nIn = 2, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/chargingTime) annotation(
Placement(transformation(origin = {-288, 144}, extent = {{10, -10}, {-10, 10}})));
// Stochastic Transition: Car picked up for “long” maintenance (e.g. due to an incident/ accident) by service provider
PNlib.Components.TES TCM(nIn = 1, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/chargingTime) annotation(
Placement(transformation(origin = {216, 142}, extent = {{-10, -10}, {10, 10}})));
// Discrete Place: Cars under maintainance
PNlib.Components.PD PCM(nIn = 1, nOut = 1, startTokens = 2) annotation(
Placement(transformation(origin = {382, 178}, extent = {{-10, -10}, {10, 10}})));
// Stochastic Transition: After maintenance, car is parked at the station Park. It is ready and available for users
PNlib.Components.TES TMPR(nIn = 1, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/usageTime) annotation(
Placement(transformation(origin = {384, 74}, extent = {{-10, -10}, {10, 10}})));
// Discrete Place: Car in use by customers
PNlib.Components.PD PCU_1(nIn = 2, nOut = 1, startTokens = 3) annotation(
Placement(transformation(origin = {392, -8}, extent = {{10, -10}, {-10, 10}})));
// Stochastic Transition: The car is ready and available for other users, after its charging operation
PNlib.Components.TES TCPR(nIn = 1, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/returnRate) annotation(
Placement(transformation(origin = {342, -94}, extent = {{-10, -10}, {10, 10}})));
// Discrete Place: Car in use by customers
PNlib.Components.PD PCU_2(nIn = 1, nOut = 1, startTokens = 1) annotation(
Placement(transformation(origin = {252, -130}, extent = {{-10, -10}, {10, 10}})));
// Stochastic transition: Car return to station Park by user. This car will be in charging operation
PNlib.Components.TES TCPc(nIn = 1, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/usageTime) annotation(
Placement(transformation(origin = {166, -92}, extent = {{-10, -10}, {10, 10}})));
// Immediate Transition: User demand “satisfied” and then “user departure” from station park
PNlib.Components.T TUSp(nIn = 2, nOut = 1) annotation(
Placement(transformation(origin = {117, -7}, extent = {{21, -21}, {-21, 21}})));
// Stochastic Transition: User demand arrival at station park
PNlib.Components.TES TUDp(nIn = 0, nOut = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/userPatience) annotation(
Placement(transformation(origin = {336, 72}, extent = {{10, -10}, {-10, 10}})));
// Helper transition
PNlib.Components.PD P1(nIn = 1, nOut = 2) annotation(
Placement(transformation(origin = {278, 74}, extent = {{10, -10}, {-10, 10}})));
// Stochastic Transition: User demand “not satisfied” at Park. The user leaves the station without having been served
PNlib.Components.TDS TUNp(nIn = 1, distributionType = PNlib.Types.DistributionType.Exponential, h = 1/userPatience) annotation(
Placement(transformation(origin = {144, 82}, extent = {{10, -10}, {-10, 10}})));
inner PNlib.Components.Settings settings(showTokenFlow = true) annotation(
Placement(transformation(origin = {-356, 208}, extent = {{-10, -10}, {10, 10}})));
equation
// Update total waiting time when users leave
when change(PSDi.tokenFlow.outflow[2]) then
usersLeaving = PSDi.tokenFlow.outflow[2]; // Number of users leaving
totalWaitingTime = pre(totalWaitingTime) + usersLeaving * userPatience;
end when;
// Update total number of cars rented
when change(PSRi.tokenFlow.outflow[1]) then
totalCarsRented = PSRi.tokenFlow.outflow[1];
end when;
// Connections
connect(TUDi.outPlaces, PSDi.inTransition) annotation(
Line(points = {{-309.2, 10}, {-279.2, 10}}, thickness = 0.5));
connect(PSRi.outTransition[1], TUSi.inPlaces[1]) annotation(
Line(points = {{-231.2, 82}, {-207.2, 82}}, thickness = 0.5));
connect(PSDi.outTransition[1], TUSi.inPlaces[2]) annotation(
Line(points = {{-259.2, 10}, {-213.2, 10}, {-213.2, 82}, {-207.2, 82}}, thickness = 0.5));
connect(PSDi.outTransition[2], TUNi.inPlaces[1]) annotation(
Line(points = {{-259.2, 10}, {-183.2, 10}}, thickness = 0.5));
connect(PSCi.outTransition[1], TCCi.inPlaces[1]) annotation(
Line(points = {{-250.8, 116}, {-267, 116}, {-267, 144}, {-283, 144}}, thickness = 0.5));
connect(TCCi.outPlaces[1], PSCii.inTransition[1]) annotation(
Line(points = {{-293, 144}, {-308.8, 144}, {-308.8, 100}, {-306.6, 100}}, thickness = 0.5));
connect(PSCii.outTransition[1], TCRi.inPlaces[1]) annotation(
Line(points = {{-306, 79.2}, {-282, 79.2}, {-282, 53.2}}, thickness = 0.5));
connect(TCRi.outPlaces[1], PSRi.inTransition[1]) annotation(
Line(points = {{-273.2, 54}, {-251.2, 54}, {-251.2, 82}}, thickness = 0.5));
connect(TCM.outPlaces[1], PCM.inTransition[1]) annotation(
Line(points = {{221, 142}, {261, 142}, {261, 178}, {371, 178}}, thickness = 0.5));
connect(PCM.outTransition[1], TMPR.inPlaces[1]) annotation(
Line(points = {{393, 178}, {407, 178}, {407, 80.5}, {379, 80.5}, {379, 74}}, thickness = 0.5));
connect(TMPR.outPlaces[1], PCU_1.inTransition[1]) annotation(
Line(points = {{389, 74}, {450, 74}, {450, -8}, {403, -8}}, thickness = 0.5));
connect(TCPR.outPlaces[1], PCU_1.inTransition[2]) annotation(
Line(points = {{347, -94}, {347, -51}, {403, -51}, {403, -8}}, thickness = 0.5));
connect(PCU_2.outTransition[1], TCPR.inPlaces[1]) annotation(
Line(points = {{263, -130}, {337, -130}, {337, -94}}, thickness = 0.5));
connect(TCPc.outPlaces[1], PCU_2.inTransition[1]) annotation(
Line(points = {{171, -92}, {241, -92}, {241, -130}}, thickness = 0.5));
connect(PCU_1.outTransition[1], TUSp.inPlaces[1]) annotation(
Line(points = {{381, -8}, {127, -8}, {127, -7}}, thickness = 0.5));
connect(TUDp.outPlaces[1], P1.inTransition[1]) annotation(
Line(points = {{331, 72}, {326, 72}, {326, 74}, {289, 74}}, thickness = 0.5));
connect(P1.outTransition[1], TUNp.inPlaces[1]) annotation(
Line(points = {{267, 74}, {149, 74}, {149, 82}}, thickness = 0.5));
connect(P1.outTransition[2], TUSp.inPlaces[2]) annotation(
Line(points = {{267, 74}, {242, 74}, {242, 22}, {127, 22}, {127, -7}}, thickness = 0.5));
connect(PCU.outTransition[1], TCCi.inPlaces[2]) annotation(
Line(points = {{2, 46}, {-141, 46}, {-141, 142}, {-172, 142}, {-172, 145}, {-284, 145}, {-284, 144}}, thickness = 0.5));
connect(PCU.outTransition[2], TCM.inPlaces[1]) annotation(
Line(points = {{2, 46}, {107, 46}, {107, 140}, {12, 140}, {12, 93}, {212, 93}, {212, 142}}, thickness = 0.5));
connect(PCU.outTransition[3], TCPc.inPlaces[1]) annotation(
Line(points = {{2, 46}, {162, 46}, {162, -92}}, thickness = 0.5));
connect(TUSi.outPlaces[1], PCU.inTransition[1]) annotation(
Line(points = {{-196, 82}, {2, 82}, {2, 0}}, thickness = 0.5));
connect(TUSi.outPlaces[2], PSCi.inTransition[1]) annotation(
Line(points = {{-196, 82}, {-157, 82}, {-157, 116}, {-230, 116}}, thickness = 0.5));
connect(TUSp.outPlaces[1], PCU.inTransition[2]) annotation(
Line(points = {{106, -6}, {2, -6}, {2, 0}}, thickness = 0.5));
annotation(
uses(PNlib(version = "3.0.0"), Modelica(version = "4.0.0")),
Diagram(graphics = {Text(origin = {-337, -14}, extent = {{3, 0}, {-3, 0}}, textString = "text"), Text(origin = {-304, 192}, extent = {{42, -20}, {-42, 0}}, textString = "Station subnet"), Rectangle(origin = {-245, 103}, lineColor = {0, 0, 255}, lineThickness = 0.5, extent = {{-103, 71}, {103, -71}}), Rectangle(origin = {-257, 5}, lineColor = {0, 255, 0}, lineThickness = 0.5, extent = {{-91, 23}, {91, -23}}), Text(origin = {-304, -20}, extent = {{42, -20}, {-42, 0}}, textString = "User demand subnet"), Rectangle(origin = {224, 30}, lineColor = {0, 170, 255}, lineThickness = 0.5, extent = {{-132, 72}, {132, -72}}), Text(origin = {121, 136}, extent = {{57, -48}, {-57, 0}}, textString = "User Demand (park) subnet"), Polygon(origin = {342, 55}, lineColor = {255, 85, 255}, lineThickness = 0.5, points = {{-154, 111}, {-154, 57}, {32, 57}, {32, -139}, {142, -139}, {142, 137}, {-154, 137}, {-154, 127}, {-154, 111}}), Text(origin = {273, 201}, extent = {{-81, 25}, {81, -25}}, textString = "Car Maintenance (Center) subnet"), Rectangle(origin = {293, -77}, lineColor = {85, 85, 0}, lineThickness = 0.5, extent = {{-145, 87}, {145, -87}}), Text(origin = {227, -176}, extent = {{-73, 20}, {73, -20}}, textString = "Car-Sharing Park (Center) subnet"), Text(extent = {{-16, 40}, {-16, 40}}, textString = "text"), Text(origin = {-38, 62}, extent = {{-26, 16}, {26, -16}}, textString = "Cars in use"), Text(origin = {-339, 67}, extent = {{-37, 35}, {37, -35}}, textString = "Charging of cars"), Text(origin = {-204, 63}, extent = {{-32, 7}, {32, -7}}, textString = "Cars are ready")}, coordinateSystem(extent = {{-380, 240}, {500, -200}})),
version = "");
end CarSharingSystemCaseStudy;
......@@ -41,4 +41,34 @@ This model generates some stochastic user (demands), you can simulate:
Here you will find a gif to visualize the simulation result.
![](./PN4ECSS.gif)
\ No newline at end of file
<<<<<<< HEAD
![](./PN4ECSS.gif)
=======
![](./PN4ECSS.gif)
## How Tokens are Generated and Flow Through the Model
#### 1. User Arrival and Demand (TUDi and TUDp)
* Tokens representing user demand are generated at the `TUDi` and `TUDp` transitions, which simulate user arrivals at the station and park, respectively. The rate of token generation is governed by an exponential distribution based on `userPatience`.
#### 2. Users Waiting (PSDi)
* Arriving users are represented as tokens in the `PSDi` place, where they wait for available cars. If cars are available, tokens (users) will move to the `TUSi` transition where they pick up a car.
#### 3. Car Pickup and Usage (TUSi and PCU)
* Tokens (users) that successfully pick up cars move to the `PCU` place, representing cars in use by customers. This transition reduces the number of tokens in the `PSRi` place (cars ready) and increases the tokens in `PCU` (cars in use).
#### 4. Car Return and Charging (TCCi, TCRi, and PSCii)
* After usage, cars are returned and go through a charging process. The `TCCi` transition moves tokens from `PCU` to `PSCii` (charging state). Once charging is complete, tokens move through `TCRi` back to `PSRi` (cars ready).
#### 5. Car Maintenance (TCM, TMPR, and PCM)
* Occasionally, cars require maintenance. The `TCM` transition moves tokens to `PCM` (cars under maintenance). After maintenance, tokens move back to the `TMPR` transition, eventually returning to the pool of available cars.
#### 6. User Departure (TUNi and TUNp)
* If a user waits too long for a car, they leave the system. This is represented by the `TUNi` and `TUNp` transitions, which move tokens from the `PSDi` place without satisfying their demand.
>>>>>>> origin/master
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment