/*
this program is a simulation of a man and his air conditioner
when the man is warm, he turns on the AC, otherwise, he turns it off
when the AC is on and it's warm, it cools the air
if the AC is off, the temperature stays the same or goes up
if the temperature goes out of range, the program stops
*/
seq splitter3 inputs int i1, outputs int o1, int o2, int o3 {
int a;
a <- i1;
par {
a -> o1;
a -> o2;
a -> o3;
}
}
seq thermostat inputs bool power, int temp outputs bool compressor {
if (power == true && temp > 70) {
true -> compressor;
} else {
false -> compressor;
}
}
seq AC inputs bool compressor, int temp outputs int temp2 {
int t;
t <- temp;
if (compressor) {
t = t - 1;
} else {
alt {
t = t + 1;
any;
}
}
t -> temp2;
}
seq man inputs int temp outputs bool power {
if (temp > 75) {
power <- true;
} else {
power <- false;
}
}
seq main {
while (temp >= 40 && temp <= 110) {
par {
temp -> splitter3 -> temp1, temp2, temp3;
power, temp1 -> thermostat -> compressor;
compressor, temp3 -> AC -> temp;
temp2 -> man -> power;
}
}
}
|