Skip to content

Commit

Permalink
Results generated and readme done (#7)
Browse files Browse the repository at this point in the history
* Added results file

* Create README.md

* Added result images

* Update README.md

* Removed unused package
  • Loading branch information
vaquierm authored Mar 10, 2020
1 parent adbbef1 commit 9579f2a
Show file tree
Hide file tree
Showing 32 changed files with 177 additions and 94,034 deletions.
85 changes: 0 additions & 85 deletions ElevatorSimulator/Config/peterson_building.json

This file was deleted.

37 changes: 0 additions & 37 deletions ElevatorSimulator/Config/small_building.json

This file was deleted.

44 changes: 39 additions & 5 deletions ElevatorSimulator/ElevatorSimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,49 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ElevatorSimulator
{
class ElevatorSimulation
{
static void Main(string[] args)
{
var config_files = Directory.GetFiles("./", "*.json");
var config = new SimulationConfiguration(
25, // Number of simulation days
86400, // Number of ticks per day. Here one tick equals one second
3, // Number of elevators
1, // Energy per tick
"OPTIMIZED", // AI type (options are 'REGULAR', 'OPTIMIZED', 'BENCHMARK')
true, // Enable smart relocation
"DAY_CYCLES", // Request generator types (options are 'DAY_CYCLES', 'UNIFORM')
34, // Number of building floors
1, // Elevator speed in floors per tick
5, // Ticks needed to load or unload a passenger
new uint[] { 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21, 21, 21, 21, 21, 19, 19, 19, 19, 19, 19, 19, 16, 16, 14, 14, 14, 14, 12, 10 },
// Residents on each floor
new uint[] { 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1 }
// Interest per floor
);

foreach (var config_file in config_files)
Console.WriteLine("Configuration:\n" + config);

var averageRequestsPerResidentPerDayList = new uint[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var simReports = new MetricsReport[averageRequestsPerResidentPerDayList.Count()];

for (int i = 0; i < simReports.Count(); i++)
{
var config = JsonConvert.DeserializeObject<SimulationConfiguration>(File.ReadAllText(config_file));
var averageRequestsPerResidentPerDay = averageRequestsPerResidentPerDayList[i];

Console.WriteLine("Configuration:\n" + config);
Console.WriteLine("Average requests per residents per day: " + averageRequestsPerResidentPerDay);

config.AverageRequestsPerResidentPerDay = averageRequestsPerResidentPerDay;

var report = new Simulation(config).StartSimulation();
var reportPerDay = report / new MetricsReport(config.SimulationDays, config.SimulationDays, config.SimulationDays);
var reportPerPersonPerDay = reportPerDay / new MetricsReport(config.TotalResidents, config.TotalResidents, config.TotalResidents);
var reportPerPersonPerDayPerElevatorUse = reportPerPersonPerDay / new MetricsReport(config.AverageRequestsPerResidentPerDay, config.AverageRequestsPerResidentPerDay, config.AverageRequestsPerResidentPerDay);

simReports[i] = reportPerPersonPerDayPerElevatorUse;

Console.WriteLine("\nResults: ");
Console.WriteLine(report + " total");
Expand All @@ -35,6 +57,18 @@ static void Main(string[] args)
Console.WriteLine("\n\n");

}

StringBuilder b = new StringBuilder();
b.Append("AI: " + config.AIType + ", Smart relocation: " + config.SmartRelocation + "\n");
b.Append("Average requests per person per day, Waiting time, Travel time, Total time, Energy used\n");
for (int i = 0; i < simReports.Count(); i++)
{
b.Append(averageRequestsPerResidentPerDayList[i] + ", " + simReports[i].WaitingTime + ", " + simReports[i].TravelTime + ", " + simReports[i].TotalTime + ", " + simReports[i].EnergyUsed + "\n");
}

string filePath = @"results.csv";
File.WriteAllText(filePath, b.ToString());

Console.ReadKey();
}
}
Expand Down
4 changes: 0 additions & 4 deletions ElevatorSimulator/ElevatorSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -67,7 +64,6 @@
<None Include="App.config" />
<None Include="Config\peterson_building.json" />
<None Include="Config\small_building.json" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 17 additions & 8 deletions ElevatorSimulator/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,21 @@ class SimulationConfiguration
// Rsidents per floor in an array
public readonly uint[] ResidentsPerFloor;
// Average number of requests per day per residents
public readonly uint AverageRequestsPerResidentPerDay;
private uint _averageRequestsPerResidentPerDay;
public uint AverageRequestsPerResidentPerDay
{
get {
return _averageRequestsPerResidentPerDay;
}
set
{
if (value <= 0)
{
throw new InvalidSimulationConfigException("The average number of requests a resident makes per day must be positive and non zero");
}
_averageRequestsPerResidentPerDay = value;
}
}
// Interest per floor (The main floor and prehaps floors with shared spaces have higher interest)
public readonly double[] InterestPerFloor;
// Interest per floor non normalized
Expand All @@ -111,7 +125,7 @@ public uint TotalResidents
}
}

public SimulationConfiguration(uint simulationDays, uint ticksPerDay, uint numberOfElevators, uint energyPerTick, string AIType, bool smartRelocation, string requestGeneratorType, uint buildingFloors, uint elevatorSpeed, uint loadingTime, uint[] residentsPerFloor, uint averageRequestsPerResidentPerDay, uint[] interestPerFloor)
public SimulationConfiguration(uint simulationDays, uint ticksPerDay, uint numberOfElevators, uint energyPerTick, string AIType, bool smartRelocation, string requestGeneratorType, uint buildingFloors, uint elevatorSpeed, uint loadingTime, uint[] residentsPerFloor, uint[] interestPerFloor)
{
this.SimulationDays = simulationDays;
this.TicksPerDay = ticksPerDay;
Expand All @@ -129,7 +143,7 @@ public SimulationConfiguration(uint simulationDays, uint ticksPerDay, uint numbe

this.ResidentsPerFloor = residentsPerFloor;

this.AverageRequestsPerResidentPerDay = averageRequestsPerResidentPerDay;
this.AverageRequestsPerResidentPerDay = 2;

long totalInterest = interestPerFloor.Sum(x => x);
this.InterestPerFloor = interestPerFloor.Select(interest => ((double)interest / totalInterest)).ToArray();
Expand Down Expand Up @@ -171,10 +185,6 @@ public void CheckValidity()
{
throw new InvalidSimulationConfigException("The number of simulation days must be positive and non zero");
}
if (this.AverageRequestsPerResidentPerDay <= 0)
{
throw new InvalidSimulationConfigException("The average number of requests a resident makes per day must be positive and non zero");
}
}

public override string ToString()
Expand All @@ -194,7 +204,6 @@ public override string ToString()
builder.Append("Elevator speed: " + this.ElevatorSpeed + "\n");

builder.Append("Loading time: " + this.LoadingTime + "\n");
builder.Append("Average requests per person per day: " + this.AverageRequestsPerResidentPerDay + "\n");

builder.Append("Residents per floor: [" + string.Join(", ", this.ResidentsPerFloor) + "]\n");
builder.Append("Interest per floor: [" + string.Join(", ", this.InterestPerFloorNonNormalized) + "]\n");
Expand Down
4 changes: 0 additions & 4 deletions ElevatorSimulator/packages.config

This file was deleted.

Loading

0 comments on commit 9579f2a

Please sign in to comment.