0% found this document useful (0 votes)
69 views8 pages

Improvised Algorithm

This document describes an algorithm for assigning student seats in a classroom. It initializes arrays to store seat assignments, subject codes, student rolls, hall/room details. It then checks the capacity of each hall and assigns seats, ensuring no two adjacent seats are assigned the same subject. The main steps are: 1) Initialize arrays to store data 2) Check each hall's capacity and adjust limits if needed 3) Assign seats to students in each hall, skipping seats if the same subject is in an adjacent seat 4) Check that the final seating arrangement follows the graph coloring rule of no adjacent same-subjects
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)
69 views8 pages

Improvised Algorithm

This document describes an algorithm for assigning student seats in a classroom. It initializes arrays to store seat assignments, subject codes, student rolls, hall/room details. It then checks the capacity of each hall and assigns seats, ensuring no two adjacent seats are assigned the same subject. The main steps are: 1) Initialize arrays to store data 2) Check each hall's capacity and adjust limits if needed 3) Assign seats to students in each hall, skipping seats if the same subject is in an adjacent seat 4) Check that the final seating arrangement follows the graph coloring rule of no adjacent same-subjects
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

IMPROVISED ALGORITHM

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","null","null"},

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

{"12bec059","null","null","null","null","null","null","null","null","null","null","null"}
};

static string[] hallname = { "a201" ,"a202","a203"};


static int[] Row = { 2,2,2 };
static int[] Column = { 5,5,5};
static int[] Capacity = new int[100];
static int[] TempCapacity = new int[100];
static int[] CapacityPercent = new int[100];
static int grouplimit = 3, cgrouplimit = 3, limit, noofgroups =
3,TotalCapacity=0,NeedPercent,breakvalue=0,HallsToReduceLimit;
static int ReducePercent, ReduceCapacity, HoldCapacity;
static int[] groups = new int[100];
static int[] rolllimit = new int[100];
static bool check(int check)
{
if (CapacityPercent[check] < 50)
return false;
else
return true;
}
static void CapacityLimit(int hall)
{
if (CapacityPercent[hall] < 50)
{
NeedPercent = 50 - CapacityPercent[hall];
if (NeedPercent < (hall))
{
NeedPercent = ((50 * Capacity[hall]) / 100) - ((CapacityPercent[hall]
* Capacity[hall]) / 100);
ReduceCapacity = 1;
HallsToReduceLimit = (hall - 1) - NeedPercent;
}
else
{
ReducePercent = NeedPercent / (hall);
ReduceCapacity = (ReducePercent * Capacity[hall]) / 100;
HallsToReduceLimit = -1;
}
}
for (int hall1 = hall-1; hall1 > HallsToReduceLimit; hall1--)
{
if(check(hall1))
{
Capacity[hall1] -= (ReduceCapacity);
HoldCapacity += (ReduceCapacity);
Capacity[hall] = HoldCapacity;
}
}
}
static void capacityChecking()
{
try
{
int hall;
TotalCapacity =21;
for (hall = 0; hall < hallname.Length; hall++)
{
Capacity[hall] = Row[hall] * Column[hall];
if (Capacity[hall] <= TotalCapacity)
{
TotalCapacity -= Capacity[hall];
CapacityPercent[hall] = 100;
}
else if (Capacity[hall] > TotalCapacity&&TotalCapacity!=0)
{
HoldCapacity = (50 * Capacity[hall]) / 100;
if (HoldCapacity <= TotalCapacity)
TotalCapacity -= HoldCapacity;
if (HoldCapacity > TotalCapacity)
{
HoldCapacity = TotalCapacity;
TotalCapacity = 0;
}
CapacityPercent[hall] = (HoldCapacity * 100) / Capacity[hall];
CapacityLimit(hall);
}
else
{
}
}

}
catch (Exception e)
{
}

}
static void initializeseats()
{
try
{
capacityChecking();
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++)
{
breakvalue = 0;
TempCapacity[hall] = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; )
{
int assign = 1;
if (rollnosub[groups[limit], rolllimit[groups[limit]]] !=
"null")
{
initialSeat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] = subjectcode[groups[limit]];
col++;
}
else
{
assign = 0;
}

if (++rolllimit[groups[limit]] != 12)
{
limit++;
}
else
{
groups[limit] = cgrouplimit++;
limit++;
}
if (limit == grouplimit)
{
limit = 0;
}
if (assign==0)
{
continue;
}
if (TempCapacity[hall] < Capacity[hall])
{
TempCapacity[hall]++;
}
else
{
breakvalue = 1;
break;
}
}
if (breakvalue == 1)
{
break;
}
}
}
}
catch (Exception e)
{
// Console.WriteLine(e);
}

}
static bool isgraphcoloring()
{
for (int hall = 0; hall < hallname.Length; 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++)
{
try
{
breakvalue = 0;
TempCapacity[hall] = 1;
for (int row = 0; row < Row[hall]; row++)
{
for (int col = 0; col < Column[hall]; )
{
int assign = 1;
if (rollnosub[groups[limit], rolllimit[groups[limit]]] !=
"null")
{
if (row == 0)
{
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
}
else if (col!= 0)
{
if((subjectcode[groups[limit]] == initialsub[hall,
row - 1, col] && subjectcode[groups[limit]] == initialsub[hall, row, col - 1] ))
{
limit++;
if (limit == grouplimit)
{
limit = 0;
}
Seat[hall, row, col] = rollnosub[groups[limit],
rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
if (rollnosub[groups[limit],
rolllimit[groups[limit]]] == "null")
{
assign = 0;
}
}
else
{
Seat[hall, row, col] =
rollnosub[groups[limit], rolllimit[groups[limit]]];
initialsub[hall, row, col] =
subjectcode[groups[limit]];
}
}
else if (col == 0)
{
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]];
if (rollnosub[groups[limit],
rolllimit[groups[limit]]] == "null")
{
assign = 0;
}
}
else
{
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;
}
else
{
assign = 0;
}

if (++(rolllimit[groups[limit]]) != 12)
{
limit++;
}
else
{
groups[limit] = cgrouplimit++;
limit++;
}
if (limit == grouplimit)
{
limit = 0;
}
if (assign == 0)
{
continue;
}
if (TempCapacity[hall] < Capacity[hall])
{
TempCapacity[hall]++;
}
else
{
breakvalue = 1;
break;
}
}
if (breakvalue == 1)
{
break;
}
}
}
catch (Exception e)
{
//Console.WriteLine(hallname[hall] + e);
}
}
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.ReadLine();
}
static void Main(string[] args)
{
try
{
initializeseats();
if (isgraphcoloring())
{
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" + initialSeat[hall, row, col] + "
");
}
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadLine();

}
else
{
graphcolor();
}
}
catch(Exception e)
{
}
}

}
}

You might also like