...

View Full Version : automatic timetabler



sivasang
01-14-2008, 05:34 PM
hi
i am working on the automatic generation of timetable for a college using java
in the first phase of it i have scheduled the various lab hours first
now i have considered only one department with 6 semesters
at each scheduling only odd or even semesters should be allocated
each lab hour should be given 3 consecutive hours............
here each class is divided into 3 batches for the lab hours so all the three lab subject in a semester should be allocated
9 hours as 3-3 consecutive hours in the lab time table..................
in allocating so the afternoon classes should be allocated first then the morning classes...........
but the scheduling does not take place in proper way.............
i have attached the coding which i have written...........











code starts....................................

import java.io.*;
public class TimeTable {
String table1[][][]=new String[100][10][10];
String table[][][]=new String[100][10][10];
int oddeven;
int avail=0;
int flag=0;
int fl=0;
int day=0;
int hour=0;

class StaffMember {
String name;
String desi;
String sub[] = new String[2];
String lab;
String table[][]=new String[10][10];
}StaffMember staff[];

class labs{
String name;
String sub[]=new String[6];
String table[][]=new String[10][10];
}labs lab[];

class course {
String semester;
int days;
int periods;
int sec;
String sub[] = new String[6];
String lab []= new String[3];
int rooms;
int labs;
} course sem[];

private labs getlab1() throws IOException {
labs l=new labs();
l.name="cpold1";
l.sub[0]="dslab";
l.sub[1]="vblab";
l.sub[2]="sslab";
l.sub[3]="selab";
l.sub[4]="daalab";
l.sub[5]="ailab";
return l;
}

private labs getlab2() throws IOException {
labs l=new labs();
l.name="cpold2";
l.sub[0]="itlab";
l.sub[1]="dclab";
l.sub[2]="dbmslab";
l.sub[3]="cnlab";
l.sub[4]="oslab";
l.sub[5]="null";
return l;
}

private labs getlab3() throws IOException {
labs l=new labs();
l.name="eee";
l.sub[0]="eelab";
l.sub[1]="null";
l.sub[2]="null";
l.sub[3]="null";
l.sub[4]="null";
l.sub[5]="null";
return l;
}

private labs getlab4() throws IOException {
labs l=new labs();
l.name="digital";
l.sub[0]="dcfalab";
l.sub[1]="chptlab";
l.sub[2]="mplab";
l.sub[3]="null";
l.sub[4]="null";
l.sub[5]="null";
return l;
}

private labs getlab5() throws IOException {
labs l=new labs();
l.name="project";
l.sub[0]="pro1";
l.sub[1]="pro2";
l.sub[2]="null";
l.sub[3]="null";
l.sub[4]="null";
l.sub[5]="null";
return l;
}

private course getsem1details() throws IOException {
course co1=new course();
co1.semester="third sem";
co1.days=6;
co1.periods=7;
co1.sec=2;
co1.sub[0]="maths";
co1.sub[1]="edc";
co1.sub[2]="ee";
co1.sub[3]="dcfa";
co1.sub[4]="ds";
co1.sub[5]="ppl";
co1.lab[0]="eelab";
co1.lab[1]="dcfalab";
co1.lab[2]="dslab";
co1.labs=3;
co1.rooms=2;
return co1;
}

private course getsem2details() throws IOException {
course co1=new course();
co1.semester="fourth sem";
co1.days=6;
co1.periods=7;
co1.sec=2;
co1.sub[0]="m4";
co1.sub[1]="mp";
co1.sub[2]="os";
co1.sub[3]="daa";
co1.sub[4]="oops";
co1.sub[5]="cg";
co1.lab[0]="mplab";
co1.lab[1]="oslab";
co1.lab[2]="daalab";
co1.labs=3;
co1.rooms=2;
return co1;
}


private course getsem3details() throws IOException {
course co1=new course();
co1.semester="fifth sem";
co1.days=6;
co1.periods=7;
co1.sec=2;
co1.sub[0]="alc";
co1.sub[1]="ss";
co1.sub[2]="vb";
co1.sub[3]="chpt";
co1.sub[4]="ide1";
co1.sub[5]="gp";
co1.lab[0]="sslab";
co1.lab[1]="vblab";
co1.lab[2]="chptlab";
co1.labs=3;
co1.rooms=2;
return co1;
}

private course getsem4details() throws IOException {
course co1=new course();
co1.semester="sixth sem";
co1.days=6;
co1.periods=7;
co1.sec=2;
co1.sub[0]="cn";
co1.sub[1]="dbms";
co1.sub[2]="se";
co1.sub[3]="pa";
co1.sub[4]="ide2";
//co1.sub[5]="gp";
co1.lab[0]="cnlab";
co1.lab[1]="dbmslab";
co1.lab[2]="selab";
co1.labs=3;
co1.rooms=2;
return co1;
}

private course getsem5details() throws IOException {
course co1=new course();
co1.semester="seventh sem";
co1.days=6;
co1.periods=7;
co1.sec=2;
co1.sub[0]="pcd";
co1.sub[1]="ai and es";
co1.sub[2]="it and web design";
co1.sub[3]="elective1";
co1.sub[4]="elective 2";
//co1.sub[5]="";
co1.lab[0]="ailab";
co1.lab[1]="itlab";
co1.lab[2]="pro1";
co1.labs=3;
co1.rooms=2;
return co1;
}

private course getsem6details() throws IOException {
course co1=new course();
co1.semester="eight sem";
co1.days=6;
co1.periods=7;
co1.sec=2;
co1.sub[0]="EE AND MANGEMENT";
co1.sub[1]="DC";
co1.sub[2]="ES";
co1.sub[3]="elective3";
co1.sub[4]="elective 4";
co1.sub[5]="null";
co1.lab[0]="dclab";
co1.lab[1]="pro2";
co1.labs=2;
co1.rooms=2;
return co1;
}

private void getsem() throws IOException {
this.sem = new course[6];
this.sem[0] = getsem1details();
this.sem[1] = getsem2details();
this.sem[2] = getsem3details();
this.sem[3] = getsem4details();
this.sem[4] = getsem5details();
this.sem[5] = getsem6details();

this.lab=new labs[5];
this.lab[0]=getlab1();
this.lab[1]=getlab2();
this.lab[2]=getlab3();
this.lab[3]=getlab4();
this.lab[4]=getlab5();

}

private StaffMember getStaffMember(BufferedReader br, boolean promptForInput) throws IOException {
StaffMember sf = new StaffMember();
System.out.println("\n Enter the staff name");
sf.name=br.readLine();
System.out.println("\n Enter the staff Designation");
sf.desi=br.readLine();
for(int i=0; i<sf.sub.length; i++) {
if (promptForInput) { System.out.println("\n Enter the subject" + (i+1)); }
sf.sub[i]=br.readLine();
}
System.out.println("\n Enter the lab");
sf.lab=br.readLine();
for(int i=0; i<6; i++) {
for(int j=0; j<7; j++) {
sf.table[i][j]="false";
}
}
return sf;
}

private void getStaff(BufferedReader br, boolean promptForInput) throws IOException {
System.out.println("\t Enter the total number of staff ");
int totalStaff=Integer.parseInt(br.readLine());
//System.out.println("\n Enter 1 for odd semester (or) 2 for even semester");
// oddeven=Integer.parseInt(br.readLine());
this.staff = new StaffMember[totalStaff];
for(int i=0; i<totalStaff; i++) {
System.out.println("\n \tEnter the staff" + (i+1) +" details");
this.staff[i] = getStaffMember(br, promptForInput);
}
}

public void getDataFromUser() throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
getStaff(br, true);

br.close();
}

public void getDataFromFile(String fileName) throws IOException {
BufferedReader br =new BufferedReader(new FileReader(fileName));
getStaff(br, false);
//getDeparments(br, false);
br.close();
}



public void schudle(int i,String lab,String table[][][]) throws IOException{
int total=this.staff.length;

for(int m=0;m<5;m++) {
if(fl==0 && flag==0)
break;
labs l=this.lab[m];
for(int n=0;n<l.sub.length;n++){
for(int o=0; o<6; o++) {
for(int p=0; p<7; p++) {
if(l.sub[n].equals(lab) && l.table[o][p].equals("false"))
fl=0;
else
fl=1;
for(int s=0; s<total;s++) {
StaffMember sf = this.staff[s];
if(sf.lab.equals(lab) && fl==0){
flag=0;
}
else
flag=1;
for(int j=0; j<6; j++) {
for(int k=0; k<7; k++) {
if(flag==1)
break;
if(table[i][j][k].equals("false") && sf.table[j][k].equals("false") && l.table[j][k].equals("false"))
{
table[i][j][k]=lab;
table[i][j][k+1]=lab;
table[i][j][k+2]=lab;
sf.table[j][k]=lab;
sf.table[j][k+1]=lab;
sf.table[j][k+2]=lab;
l.table[j][k]=lab;
l.table[j][k+1]=lab;
l.table[j][k+2]=lab;
flag=1;
avail=1;
day=j;
hour=k;
}
else
flag=0;
}
if(avail==1)
break;
}
}
}
}
}
}

}

public void practicals(String table[][][]) throws IOException{
for(int i=0; i<6; i++) {
for(int j=5; j<7; j++) {
for(int k=0; k<7; k++) {
table[i][j][k]="true";
}
}
}
for(int i=0; i<6; i++) {
for(int j=0; j<6; j++) {
for(int k=0; k<4; k++) {
table[i][j][k]="true";
}
}

}

for(int i=0; i<5; i++) {
labs l=this.lab[i];
for(int j=0; j<6; j++) {
for(int k=0; k<7; k++) {
l.table[j][k]="false";
}
}
}
for(int i=0; i<6; i++) {
course co1= this.sem[i];
for(int j=0; j<3; j++) {
flag=0;
avail=0;
fl=1;
String temp=co1.lab[j];
schudle(i,temp,table);


for (int k=0;k<co1.labs;k++){
if(flag==1 && avail==1){

for(int m=0;m<5;m++) {
labs l=this.lab[m];
for(int n=0;n<l.sub.length;n++){
if(l.sub[n].equals(co1.lab[k]) && l.table[day][hour].equals("false"))
{
l.table[day][hour]=co1.semester;
l.table[day][hour+1]=co1.semester;
l.table[day][hour+2]=co1.semester;
}

}
}
}
}
}
}

for(int i=0; i<6; i++) {
for(int j=0; j<6; j++) {
for(int k=0; k<7; k++) {
if(table[i][j][k].equals("true"))
table[i][j][k]="false";
}
}
}

}

public void stafftable(String table[][][]) throws IOException {

System.out.println("\n\tThe time table for each staff is as follows\n");
int totalStaff=this.staff.length;
for(int i=0; i<totalStaff; i++) {
StaffMember sf = this.staff[i];
System.out.println("\nThe time table for staff " + sf.name + " is as follow\n");
for(int j=0; j<6; j++) {
for(int k=0;k<7;k++) {
System.out.print("\t");
System.out.print(sf.table[j][k]);
}
System.out.println("");
}
System.out.println("");
}



System.out.println("\n\tThe time table for each lab is as follows\n");
for(int p=0; p<5; p++) {
labs l=this.lab[p];
System.out.println("\nThe time table for the " + l.name + "lab is as follow\n");
for(int q=0; q<6; q++) {
for(int r=0; r<7; r++) {
System.out.print("\t");
System.out.print(l.table[q][r]);
}
System.out.println("");
}
System.out.println("");
}


System.out.println("\n\tThe time table for each class is as follows\n");
for(int x=0; x<6;x++) {
System.out.println("\nThe time table for " + (x+1) + " semester is as follow\n");
for(int y=0; y<6;y++) {
for(int z=0; z<7; z++) {
System.out.print("\t");
System.out.print(table[x][y][z]);
}
System.out.println("");
}
System.out.println("");
}
}

public void writeData(PrintStream writer) throws IOException {
int totalStaff=this.staff.length;
writer.println(totalStaff);
for(int i=0; i<totalStaff; i++) {
StaffMember sf = this.staff[i];
writer.println(sf.name);
writer.println(sf.desi);
for(int j=0; j<sf.sub.length; j++) {
writer.println(sf.sub[j]);
}
writer.println(sf.lab);
}
}

public void writesem(PrintStream writer) throws IOException {
int totalsem=this.sem.length;
totalsem=2;
writer.println(totalsem);
for(int i=0; i<totalsem; i++) {
course co1= this.sem[i];
writer.println(co1.semester);
writer.println(co1.days);
writer.println(co1.periods);
writer.println(co1.sec);
for(int j=0; j<co1.sub.length; j++) {
writer.println(co1.sub[j]);
}
for(int k=0; k<co1.lab.length; k++) {
writer.println(co1.lab[k]);
}
writer.println(co1.labs);
writer.println(co1.rooms);
}
}


public void writesem(String fileName) throws IOException {
PrintStream writer =new PrintStream(new FileOutputStream(fileName));
writesem(writer);
writer.close();
}

public void writeData(String fileName) throws IOException {
PrintStream writer =new PrintStream(new FileOutputStream(fileName));
writeData(writer);
writer.close();
}

public static void main(String[] args) {
TimeTable tt = new TimeTable();
try {
for(int i=0; i<6; i++) {
for(int j=0; j<6; j++) {
for(int k=0; k<7; k++) {
tt.table1[i][j][k]="false";
}
}
}
tt.getsem();
tt.getDataFromUser();
//tt.writeData(System.out);
//tt.writeData("staff.txt");
//tt.writesem(System.out);
//tt.writesem("sem.txt");
tt.practicals(tt.table1);
tt.stafftable(tt.table1);














for(int n=0; n<12;n++) {
for(int i=0; i<6; i++) {
for(int m=0;m<2;m++) {
for(int j=0; j<6; j++) {
for(int k=0; k<7; k++) {
tt.table[n][j][k]=tt.table1[i][j][k];

}
}
n++;
}
}

}




for(int x=0; x<12;x++) {

//System.out.println("\nThe time table for " + x + " semester is as follow\n");
for(int y=0; y<6;y++) {
for(int z=0; z<7; z++) {
System.out.print("\t");
System.out.print(tt.table[x][y][z]);
}
System.out.println("");

}

System.out.println("");


}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}



...............................

shyam
01-15-2008, 06:16 AM
but the scheduling does not take place in proper way.............

posting >500 lines of unformatted code and simply saying it does not work properly isn't going to get u any help...u have to clearly state what is the problem you are facing...try to narrow down where you think the problem lies and post only the relevant code

Aradon
01-15-2008, 08:47 PM
One thing you should do is go through the code line by line and look at what it's doing. If you get confused, you can come here and ask on a particular passage.

Asking us to look at your code and just "fix" it however, will not produce any intended results.

So please be more specific, here and in the future.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum