From 5e837ad8e38253f277b7e10ab3ab072173af59a9 Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Wed, 29 Jul 2020 19:24:24 +0100 Subject: [PATCH 1/2] Created a Method to check if the variable are idle or moving --- ElevatorAlgorithm/Class1.cs | 10 ++++++++ ElevatorAlgorithm/Program.cs | 50 ++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 ElevatorAlgorithm/Class1.cs diff --git a/ElevatorAlgorithm/Class1.cs b/ElevatorAlgorithm/Class1.cs new file mode 100644 index 0000000..89bbe27 --- /dev/null +++ b/ElevatorAlgorithm/Class1.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ElevatorAlgorithm +{ + class Class1 + { + } +} diff --git a/ElevatorAlgorithm/Program.cs b/ElevatorAlgorithm/Program.cs index 26e259b..3e8c596 100644 --- a/ElevatorAlgorithm/Program.cs +++ b/ElevatorAlgorithm/Program.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel.Design; namespace ElevatorAlgorithm { @@ -15,6 +16,8 @@ public interface ElevatorInterface void moveUp(int z); void moveDown(int z); void moveNext(int floor, int z); + int getIsIdle(); + int setIsIdle(int a); } @@ -26,6 +29,7 @@ public class Elevator : ElevatorInterface private int currentFloor; private int people; private int sum; + private int isIdle; public int getSum() @@ -121,8 +125,17 @@ public void moveDown(int z) } + public int getIsIdle() + { + return isIdle; + } -} + public int setIsIdle(int a) + { + this.isIdle += a; + return isIdle; + } + } class Program { @@ -141,7 +154,7 @@ static void Main(string[] args) } - Elevator change = null; // Temporary Object + Elevator change = null; // Temporary Object while (true) { @@ -163,7 +176,7 @@ static void Main(string[] args) int z = 0; - for (int i = 0; i < numFloors; i++) + for (int i = 0; i < numFloors; i++) { // Selecting the floor where people are waiting @@ -188,7 +201,7 @@ static void Main(string[] args) // Choosing the BEST ELEVATOR for that location int[] unsorted = new int[elevator.Length]; int[] sorted = new int[elevator.Length]; - + for (int j = 0; j < elevator.Length; j++) { unsorted[j] = Math.Abs(floor[i] - elevator[j].getCurrentFloor()); @@ -197,15 +210,25 @@ static void Main(string[] args) Array.Sort(sorted); - for (int k = 0; k < elevator.Length; k++) + for (int j = 0; j < sorted.Length; j++) { - if (sorted[0] == unsorted[k]) - { - change = elevator[k]; - z = k + 1; - break; - } + for (int k = 0; k < elevator.Length; k++) + { + + { + if (elevator[k].getIsIdle() == 0 && sorted[j] == unsorted[k]) + { + change = elevator[k]; + z = k + 1; + elevator[k].setIsIdle(1); + Console.WriteLine("Elevator " + z + " is selected and idle is set to " + elevator[k].getIsIdle()); + goto LoopEnd; + + } + } + } } + LoopEnd: // Acknowledging the number of people waiting for the elevator on selected floor while (true) @@ -287,13 +310,14 @@ static void Main(string[] args) } - // forwarding the values from temporary elevator object to desired elevator - // object + // forwarding the values from temporary elevator object to desired elevator object for (int k = 0; k < elevator.Length; k++) { if (z == k + 1) { elevator[k] = change; + elevator[k].setIsIdle(-1); + Console.WriteLine("Elevator " + z + " has ended its action and idle is set to " + elevator[k].getIsIdle()); break; } From 140eb6457d2fc42e2f2d14520eff0fee24a336a9 Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:22:39 +0100 Subject: [PATCH 2/2] Adding IsIdle Variablewrf --- ElevatorAlgorithm/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElevatorAlgorithm/Program.cs b/ElevatorAlgorithm/Program.cs index 3e8c596..fcc1222 100644 --- a/ElevatorAlgorithm/Program.cs +++ b/ElevatorAlgorithm/Program.cs @@ -229,7 +229,7 @@ static void Main(string[] args) } } LoopEnd: - + //sfs // Acknowledging the number of people waiting for the elevator on selected floor while (true) {