-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMachineNode.cs
More file actions
175 lines (158 loc) · 6.95 KB
/
MachineNode.cs
File metadata and controls
175 lines (158 loc) · 6.95 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
namespace Scheduler {
class MachineNode {
private int creditsScheduled;
private int majorCreditsScheduled;
private List<Machine> machines;
private int year;
private int quarter;
private Preferences preferences;
private int classesScheduled;
//------------------------------------------------------------------------------
//
// creates machine node from year and quarter
//
//------------------------------------------------------------------------------
public MachineNode(int year, int quarter) {
this.year = year;
this.quarter = quarter;
machines = new List<Machine>();
creditsScheduled = 0;
majorCreditsScheduled = 0;
classesScheduled = 0;
preferences = new Preferences();
}
//------------------------------------------------------------------------------
//
// creates machine node from scratch
//
//------------------------------------------------------------------------------
public MachineNode(List<Machine> m, int year, int quarter, Preferences p) {
this.year = year;
this.quarter = quarter;
machines = m;
creditsScheduled = 0;
majorCreditsScheduled = 0;
preferences = p;
}
//------------------------------------------------------------------------------
//
// returns year
//
//------------------------------------------------------------------------------
public int GetYear() { return year; }
//------------------------------------------------------------------------------
//
// returns wuarter
//
//------------------------------------------------------------------------------
public int GetQuarter() { return quarter; }
//------------------------------------------------------------------------------
//
// returns ALL machined
//
//------------------------------------------------------------------------------
public List<Machine> GetMachines() { return machines; }
//------------------------------------------------------------------------------
//
// returns credits currently scheduled on machine node. not implemented because
// we dont have credits in machine. we only check for classes scheduled
//------------------------------------------------------------------------------
public int GetCreditsScheduled() {
return creditsScheduled;
}
//------------------------------------------------------------------------------
//
// temporary until getcreditsscheduled is implemented
//
//------------------------------------------------------------------------------
public int GetClassesScheduled() {
return classesScheduled;
}
//------------------------------------------------------------------------------
//
// temporary until getcreditsscheduled is implemented
//
//------------------------------------------------------------------------------
public void AddClassesScheduled(int k) {
classesScheduled += k;
}
//------------------------------------------------------------------------------
//
// will work with getcreditsscheduled for preferences
//
//------------------------------------------------------------------------------
public int GetMajorCreditsScheduled() {
return majorCreditsScheduled;
}
//------------------------------------------------------------------------------
//
// adds a new machine to node
//
//------------------------------------------------------------------------------
public void AddMachine(int year, int quarter, List<DayTime> dateTime, List<Job> jobs) {
Machine m = new Machine(year, quarter, dateTime, jobs);
machines.Add(m);
}
//------------------------------------------------------------------------------
//
// adds a new machine to node
//
//------------------------------------------------------------------------------
public void AddMachine(Machine m) {
machines.Add(m);
}
//------------------------------------------------------------------------------
//
// removes machine from node
//
//------------------------------------------------------------------------------
public void RemoveMachine(Machine x) {
if (machines.Contains(x)) machines.Remove(x);
}
//------------------------------------------------------------------------------
//
// not actually used because the scheduler is in charge of this; I will keep it
// here in case it is possibly better to delegate it to this class
//------------------------------------------------------------------------------
public void ScheduleMachine(Machine x, Job j) {
if (machines.Contains(x)) {
int num = machines.IndexOf(x);
Machine m = machines[num];
if (!m.CheckInUse()) {
m.SetInUse(true);
m.SetCurrentJobProcessing(j);
} else {
Console.WriteLine("Cannot schedule -- machine is busy");
}
}
}
//------------------------------------------------------------------------------
//
// not used but here for extendability
//
//------------------------------------------------------------------------------
public void UnscheduleMachine(Machine x) {
if(machines.Contains(x)) {
int num = machines.IndexOf(x);
Machine m = machines[num];
m.SetInUse(false);
m.SetCurrentJobProcessing(null);
}
}
//------------------------------------------------------------------------------
//
// returns all machines for final plan used by scheduler
//
//------------------------------------------------------------------------------
public List<Machine> GetAllScheduledMachines() {
List<Machine> scheduledMachines = new List<Machine>();
for(int i = 0; i < machines.Count; i++ ) {
Machine m = machines[i];
if (m.CheckInUse()) scheduledMachines.Add(m);
}
return scheduledMachines;
}
}
}