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

docs update

parent 86b6c9fb
Branches
No related tags found
No related merge requests found
model CarSharingSystemSimplified
// Parameters
parameter Integer numCars = 10 "Number of cars in the system";
parameter Integer numUsers = 5 "Number of users in the system";
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 = 2.0 "Maximum waiting time for users";
// State variables for objectives
Real totalWaitingTime(start=0) "Total waiting time for users";
Real carUtilization(start=0) "Car utilization over time";
Real carsInUse(start=0) "Number of cars in use";
// Discrete Variables for Intermediate Calculations
discrete Real waitingTimeIncrement(start=0);
discrete Real carUtilizationIncrement(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) 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/userPatience) 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
// Objective Equations
// totalWaitingTime = numUsers * userPatience * (1 - returnRate); // Total waiting time is number of users multiplied by their patience
// carUtilization = (numUsers * usageTime) / (numCars * (usageTime + chargingTime + (1 / returnRate))); // Car utilization is based on usage time
// Objective Equations
// Calculate waiting time when users leave without getting a car
when change(PSDi.t) then
waitingTimeIncrement = (pre(PSDi.t) - PSDi.t) * userPatience;
totalWaitingTime = pre(totalWaitingTime) + waitingTimeIncrement;
end when;
// Calculate car utilization
when change(PSRi.t) then
carsInUse = numCars - PSRi.t;
carUtilizationIncrement = carsInUse * usageTime / (numCars * (time + Modelica.Constants.eps));
carUtilization = pre(carUtilization) + carUtilizationIncrement;
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")),
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 CarSharingSystemSimplified;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment