-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatchAgent.java
More file actions
88 lines (75 loc) · 2.1 KB
/
DispatchAgent.java
File metadata and controls
88 lines (75 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright 2018 David Prentiss
*/
package sim.app.agentcity;
import sim.util.*;
import sim.engine.*;
import java.util.Arrays;
/**
* Generic agent for dispatching {@link Vehicle} objects to {@link Person}
* objects.
*/
public class DispatchAgent implements Steppable, Dispatcher {
// MASON
private static final long serialVersionUID = 1;
Stoppable stopper;
long step;
// Properties
public final int idNum;
// Variables
private Bag vehiclePool;
private Bag clients;
private Bag idleVehicles;
// Accessors
public int requestVehicle(Intersection location,
Intersection destination,
Person person,
long step) {
if (idleVehicles.numObjs > 0) {
assignVehicle((Vehicle)idleVehicles.pop(),
person,
location,
destination);
}
return -1;
}
public int addVehicleToPool(Vehicle vehicle) {
if(vehiclePool.add(vehicle)) {
idleVehicles.add(vehicle);
return 0;
}
return -1;
}
private int assignVehicle(Vehicle vehicle,
Person person,
Intersection start,
Intersection end) {
return -1;
}
/*
@Override
public String toString() {
return new StringBuilder()
.append("DriverAgent: {")
.append("idNum: " + idNum)
.append(", ")
.append("desiredSpeed: " + desiredSpeed)
.append("}\n")
.toString();
}
*/
/** Constructor
*
* @param id (required) int label for this class. Should be unique but
* uniqueness is not checked.
*/
public DispatchAgent(int id, int poolSize) {
idNum = id;
vehiclePool = new Bag(poolSize);
idleVehicles = new Bag(poolSize);
}
public void step(final SimState state) {
AgentCity ac = (AgentCity)state;
step = ac.schedule.getSteps();
}
}