0% found this document useful (0 votes)
41 views

Algorithm Implementation Source Code:: Program

This C# code implements an algorithm to assign student seats for multiple courses in different halls/classrooms while avoiding conflicts. It initializes 2D and 3D arrays to store seat assignments and subject codes. It first tries to assign seats without conflicts, and if that fails, it runs a graph coloring algorithm to assign seats in a non-conflicting manner across rows and columns. The main method prints out the final seating arrangements for each hall.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Algorithm Implementation Source Code:: Program

This C# code implements an algorithm to assign student seats for multiple courses in different halls/classrooms while avoiding conflicts. It initializes 2D and 3D arrays to store seat assignments and subject codes. It first tries to assign seats without conflicts, and if that fails, it runs a graph coloring algorithm to assign seats in a non-conflicting manner across rows and columns. The main method prints out the final seating arrangements for each hall.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ALGORITHM IMPLEMENTATION

Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class Program
{
static string[, ,] Seat = new string[100, 100, 100];
static string[, ,] initialSeat = new string[100,100,100];
static string[, ,] initialsub = new string[100,100,100];
static string[] subjectcode = { "11cs101", "11ee203", "11ec309" };
static string[,] rollnosub ={

{"12bcs059","12bcs060","12bcs061","12bcs062","12bcs063","12bcs064","12bcs065","12bcs066",
"12bcs067","12bcs068"},

{"12bee059","12bee060","12bee061","12bee062","12bee063","12bee064","12bee065","12bee066",
"12bee067","12bee068"},

{"12bec059","12bec060","12bec061","12bec062","12bec063","12bec064","12bec065","12bec066",
"12bec067","12bec068"},
};
static string[] hallname = { "a201", "a202", "a203" };
static int[] Row = { 5, 5, 5 };
static int[] Column = { 2, 2, 2 };
static int grouplimit = 3, cgrouplimit = 3, limit, noofgroups = 3;

static int[] groups = new int[100];


static int[] rolllimit = new int[100];
static void initializeseats()
{
for (limit = 0; limit < grouplimit; limit++)
{
groups[limit] = limit;
}
for (limit = 0; limit < noofgroups; limit++)
{
rolllimit[limit] = 0;
}
limit = 0;
for (int hall = 0; hall < hallname.Length; hall++)
{
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; )
{
initialSeat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] = subjectcode[groups[limit]];
col++;
if (++rolllimit[groups[limit]] != 10)
{
limit++;
}
else
{
groups[limit] = cgrouplimit++;
limit++;
}
if (limit == grouplimit)
{
limit = 0;
}
}
}
}
}
static bool isgraphcoloring(int hall)
{
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; col++)
{
if ((row != 0) && (col != 0))
{
if (initialsub[hall, row, col] == initialsub[hall, row - 1, col]
|| initialsub[hall, row, col] == initialsub[hall, row, col - 1])
{
return false;
}
}
else if (row == 0 && col == 0)
{
}
else if (col == 0)
{
if (initialsub[hall, row, col] == initialsub[hall, row - 1, col])
{
return false;
}
}
else if (row == 0)
{
if (initialsub[hall, row, col] == initialsub[hall, row, col - 1])
{

return false;
}
}

else
{
}

}
}
return true;
}
static void graphcolor()
{
cgrouplimit = grouplimit;
for (limit = 0; limit < grouplimit; limit++)
{
groups[limit] = limit;
}
for (limit = 0; limit < noofgroups; limit++)
{
rolllimit[limit] = 0;
}
limit = 0;
for (int hall = 0; hall < hallname.Length; hall++)
{
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; )
{

if (row == 0)
{
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] = subjectcode[groups[limit]];
}
else
{
if (subjectcode[groups[limit]] == initialsub[hall, row -
1, col])
{
limit++;
if (limit == grouplimit)
{
limit = 0;
}
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
}
else
{
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
}
}

++col;

if (++(rolllimit[groups[limit]]) != 10)
{
limit++;
}
else
{
groups[limit] = cgrouplimit++;
limit++;
}
if (limit == grouplimit)
{
limit = 0;
}

}
}
Console.ReadLine();
}
static void Main(string[] args)
{
try
{
initializeseats();
for (int hall = 0; hall < hallname.Length; hall++)
{
if (isgraphcoloring(hall))
{
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; col++)
{
Seat[hall, row, col] = initialSeat[hall, row, col];
}
}
}
else
{
graphcolor();
}
}
Console.WriteLine("**************SEATING ARRANGEMENTS**************");
for (int hall = 0; hall < hallname.Length; hall++)
{
Console.WriteLine("HALL NUMBER = "+hallname[hall]);
int seatno = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int seatnum = 0; seatnum < Column[hall]; seatnum++)
{
Console.Write("\t "+seatno++ +" ");
}
Console.WriteLine();
for (int col = 0; col < Column[hall]; col++)
{
Console.Write("\t"+Seat[hall, row, col] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
Console.Read();
}
catch(Exception e)
{
}
}

}
}

You might also like