Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Docs/Task 3.pptx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

257 changes: 257 additions & 0 deletions InventorySimulation/.vs/InventorySimulation/v17/DocumentLayout.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ShowEmptyProjects":false,"CustomColumnOrderings":{"name":0,"type":1,"neutral-value":2,"neutral-comment":3},"ShowValidationErrors":true,"SelectedResourceGroupsByProjectFilePath":{"D:\\Projects\\Modelling-and-Simulation\\InventorySimulation\\InventorySimulation\\InventorySimulation.csproj":["D:\\Projects\\Modelling-and-Simulation\\InventorySimulation\\InventorySimulation\\Form1.resx"]},"VisibleColumnKeys":["name","neutral-value","neutral-comment"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"RootPath":"D:\\Projects\\Modelling-and-Simulation\\InventorySimulation\\InventoryModels","ProjectFileName":"InventoryModels.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"SimulationCase.cs"},{"SourceFile":"Distribution.cs"},{"SourceFile":"Properties\\AssemblyInfo.cs"},{"SourceFile":"PerformanceMeasures.cs"},{"SourceFile":"SimulationSystem.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.5.2.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\Microsoft.CSharp.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.Data.DataSetExtensions.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.Net.Http.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.2\\System.Xml.Linq.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"D:\\Projects\\Modelling-and-Simulation\\InventorySimulation\\InventoryModels\\bin\\Debug\\InventoryModels.dll","OutputItemRelativePath":"InventoryModels.dll"},{"OutputItemFullPath":"","OutputItemRelativePath":""}],"CopyToOutputEntries":[]}
21 changes: 21 additions & 0 deletions InventorySimulation/InventoryModels/Distribution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InventoryModels
{
public class Distribution
{
public Distribution()
{

}
public int Value { get; set; }
public decimal Probability { get; set; }
public decimal CummProbability { get; set; }
public int MinRange { get; set; }
public int MaxRange { get; set; }
}
}
60 changes: 60 additions & 0 deletions InventorySimulation/InventoryModels/InventoryModels.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AF5CF0AE-2D6B-4A56-BC72-78A2E269F255}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>InventoryModels</RootNamespace>
<AssemblyName>InventoryModels</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Services\DistributionManager.cs" />
<Compile Include="Services\LCG.cs" />
<Compile Include="Services\SimulationEngine.cs" />
<Compile Include="SimulationCase.cs" />
<Compile Include="Distribution.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PerformanceMeasures.cs" />
<Compile Include="SimulationSystem.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
19 changes: 19 additions & 0 deletions InventorySimulation/InventoryModels/PerformanceMeasures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InventoryModels
{
public class PerformanceMeasures
{
public PerformanceMeasures()
{

}
public decimal EndingInventoryAverage { get; set; }

public decimal ShortageQuantityAverage { get; set; }
}
}
36 changes: 36 additions & 0 deletions InventorySimulation/InventoryModels/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("InventoryModels")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InventoryModels")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("af5cf0ae-2d6b-4a56-bc72-78a2e269f255")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InventoryModels.Services
{
internal class DistributionManager
{
public int GenerateDemandValue(List<Distribution> distribution, int randN)
{
return GenerateTimeFromDistribution(distribution, randN);
}

public int GenerateLeadDaysValue(List<Distribution> distribution, int randN)
{
return GenerateTimeFromDistribution(distribution, randN);
}
private int GenerateTimeFromDistribution(List<Distribution> distribution, int randN)
{
// Handle edge cases
if (distribution == null || distribution.Count == 0)
throw new ArgumentException("Distribution cannot be null or empty");

if (randN < 1 || randN > 100)
throw new ArgumentException("Random number must be between 1 and 100");

int l = 0, r = distribution.Count - 1, mid;
while (l <= r)
{
mid = l + (r - l) / 2;
var dist = distribution[mid];
if (randN < dist.MinRange)
r = mid - 1;
else if (randN > dist.MaxRange)
l = mid + 1;
else
return dist.Value;
}

// Fallback: return first distribution time
return distribution.First().Value;
}
}
}
45 changes: 45 additions & 0 deletions InventorySimulation/InventoryModels/Services/LCG.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.CSharp.RuntimeBinder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace InventoryModels.Services
{
public class LCG
{
private long seed;
private readonly long Mod;
private readonly long Multiplier;
private readonly long Increment;
public LCG(long z0, long mod ,long mult, long inc)
{
seed = z0;
Mod = mod;
Multiplier = mult;
Increment = inc;
}
public LCG()
{
seed = DateTime.Now.Ticks;
Mod = 2147483647;
Multiplier = 48271;
Increment = 0;
}
public long Next()
{
return seed = (Multiplier * seed + Increment) % Mod;
}

public long Next(long l,long r)
{
seed = (Multiplier * seed + Increment) % Mod;

long range = r - l + 1;
return ( l + (seed % range) );

}
}
}
123 changes: 123 additions & 0 deletions InventorySimulation/InventoryModels/Services/SimulationEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.Text;
using System.Threading.Tasks;

namespace InventoryModels.Services
{
public class SimulationEngine
{
LCG rand;
SimulationSystem simulationSystem;
DistributionManager distributionManager;

int ArriveDay = 0;
int Quantity = 0;

public SimulationEngine(SimulationSystem ss)
{
simulationSystem = ss;
rand = new LCG();
distributionManager = new DistributionManager();
ArriveDay = simulationSystem.StartLeadDays + 1;
Quantity = simulationSystem.StartOrderQuantity;
}
SimulationCase SimulateDay()
{
SimulationCase simCase = new SimulationCase();

simCase.Day = simulationSystem.SimulationTable.Last().Day + 1;
if (simCase.Day % simulationSystem.ReviewPeriod == 1)
{
simCase.Cycle = simulationSystem.SimulationTable.Last().Cycle + 1;
}
else
{
simCase.Cycle = simulationSystem.SimulationTable.Last().Cycle;
}

simCase.DayWithinCycle = simCase.Day % simulationSystem.ReviewPeriod;
if(simCase.DayWithinCycle == 0)
simCase.DayWithinCycle = simulationSystem.ReviewPeriod;

if (simCase.Day == ArriveDay)
{
simCase.BeginningInventory = simulationSystem.SimulationTable.Last().EndingInventory + Quantity;
ArriveDay = 0;
Quantity = 0;
}
else
{
simCase.BeginningInventory = simulationSystem.SimulationTable.Last().EndingInventory;
}

simCase.RandomDemand = (int)rand.Next(1, 100);
simCase.Demand = distributionManager.GenerateDemandValue(simulationSystem.DemandDistribution, simCase.RandomDemand);
simCase.EndingInventory = Math.Max(0, simCase.BeginningInventory - (simCase.Demand + simulationSystem.SimulationTable.Last().ShortageQuantity));
simCase.ShortageQuantity = -Math.Min(0, simCase.BeginningInventory - (simCase.Demand + simulationSystem.SimulationTable.Last().ShortageQuantity));

if (simCase.Day % simulationSystem.ReviewPeriod == 0)
{
simCase.OrderQuantity = simulationSystem.OrderUpTo - simCase.EndingInventory + simCase.ShortageQuantity;
simCase.RandomLeadDays = (int)rand.Next(1, 100);
simCase.LeadDays = distributionManager.GenerateLeadDaysValue(simulationSystem.LeadDaysDistribution, simCase.RandomLeadDays);
Quantity = simCase.OrderQuantity;
ArriveDay = simCase.Day + simCase.LeadDays + 1;
}
else
{
simCase.OrderQuantity = 0;
simCase.RandomLeadDays = 0;
simCase.LeadDays = 0;
}
return simCase;
}
public void CalcPreformace()
{
int totalEndingInventory = 0;
int totalShortageQuantity = 0;

for(int i = 0; i < simulationSystem.SimulationTable.Count; i++)
{
totalEndingInventory += simulationSystem.SimulationTable[i].EndingInventory;
totalShortageQuantity += simulationSystem.SimulationTable[i].ShortageQuantity;
}

simulationSystem.PerformanceMeasures.EndingInventoryAverage = (decimal)totalEndingInventory / simulationSystem.SimulationTable.Count;
simulationSystem.PerformanceMeasures.ShortageQuantityAverage = (decimal)totalShortageQuantity / simulationSystem.SimulationTable.Count;
}
public void RunSimulation()
{
simulationSystem.SimulationTable.Clear();
int NumOfDays = simulationSystem.NumberOfDays;

SimulationCase simCase = new SimulationCase();

simCase.Day = 1;
simCase.Cycle = 1;
simCase.DayWithinCycle = 1;

simCase.BeginningInventory = simulationSystem.StartInventoryQuantity;

simCase.RandomDemand = (int)rand.Next(1, 100);
simCase.Demand = distributionManager.GenerateDemandValue(simulationSystem.DemandDistribution, simCase.RandomDemand);
simCase.EndingInventory = Math.Max(0, simCase.BeginningInventory - simCase.Demand);
simCase.ShortageQuantity = -Math.Min(0, simCase.BeginningInventory - simCase.Demand);

simCase.OrderQuantity = 0;
simCase.RandomLeadDays = 0;
simCase.LeadDays = 0;
//simCase.LeadDays = simulationSystem.StartLeadDays;

simulationSystem.SimulationTable.Add(simCase);

for (int i = 2; i <= NumOfDays; i++)
{
SimulationCase cur = SimulateDay();
simulationSystem.SimulationTable.Add(cur);
}
}
}
}
27 changes: 27 additions & 0 deletions InventorySimulation/InventoryModels/SimulationCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InventoryModels
{
public class SimulationCase
{
public SimulationCase()
{

}
public int Day { get; set; }
public int Cycle { get; set; }
public int DayWithinCycle { get; set; }
public int BeginningInventory { get; set; }
public int RandomDemand { get; set; }
public int Demand { get; set; }
public int EndingInventory { get; set; }
public int ShortageQuantity { get; set; }
public int OrderQuantity { get; set; }
public int RandomLeadDays { get; set; }
public int LeadDays { get; set; }
}
}
Loading