Pages

Sunday, May 31, 2009

i in still seaching who i am

i fell like, I'm a one little tree that trying to survive in the bush. competing was really hard, but i have to make it success as well as i can in order to live. I'm trying to make my root become stronger, try my hard to get all the need, look around try to follow the way how the other big tree to grow like them.

uhhhm... so hard to survive. sometime got so blur...who I'm gone be. in d age of 22nd still finding my identity, the way i perform my self, the way i present to the people....still in searching. sometime i need a person who can guide me, tell me, advise me to follow the right way... and I'm glad to have them...and i would like to say thanks....

People come and people go And people gonna come some more...and they teaching me to be who i am now. lots i can see,lots i can make as guided for me. what should i do, and i shouldn't.

lots of people i can see, bad one, good... umhhh i chose to a be good one. insyallah my god bless me, may god pelihara aku. i pray for that. peliharlah aku dari semua kemungkaran perkara yang engkau laknat, kuatkan iman aku. "amin ya robal alamin"

Sunday, May 24, 2009

My GA

/**
* Write a description of class minipro here.
*
* @author (Siti Asmah Ab Aziz & Siti Farah Diana bt Yusoff)
* @version (BinaryTournament )
*/
import javax.swing.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class miniproBinaryTournament
{
public static void main(String[]args)throws IOException
{

PrintWriter print = null;
try // try clause
{
String filename=JOptionPane.showInputDialog(null,"Enter name of file for output result"); //location for output to display
print = new PrintWriter(new FileOutputStream(filename+".txt"));

String tit=JOptionPane.showInputDialog(null,"Enter number of title offered");
int title=Integer.parseInt(tit);

String stud=JOptionPane.showInputDialog(null,"Enter Number of Student");
int student=Integer.parseInt(stud);

String pop=JOptionPane.showInputDialog(null,"Enter Number of population ");
int population=Integer.parseInt(pop);

String gen=JOptionPane.showInputDialog(null,"Enter Number of generation ");
int generation=Integer.parseInt(gen);

//number of student

Random generator = new Random();
int[][] aMatrix = new int[student][4];
String out="";
// populate matrix
for (int i = 0; i <>

for (int j = 0; j <>

//number of assignment
//String assign=JOptionPane.showInputDialog(null,"Enter Number of assignment you prefer student no: " +(i+1));
//int assignment=Integer.parseInt(assign);
//int index=j+1;
int r=generator.nextInt(title);
if(r ==1)
{
aMatrix[i][j] = r;
}else
{
aMatrix[i][j] = r;}
}
}

// print matrix
print.println("Student"+"\t First Choice"+" \t Second Choice"+" \t Third Choice");
print.println("_____________________________________________________________");
for (int i = 0; i

print.println(i+1+".");

for (int j = 0; j <>

}
print.println();
print.println("_____________________________________________________________");
}
print.println();

//create chromosome
int prio=0;
int choosenP=0;
int []chromosom=new int [student];
int [] a=new int[3];
int[][] aMatrix2 = new int[student][4];
int[][] aMatrix3 = new int[student][4];
String[][] aMatrix4 = new String[student][4];
int[][] aMatrix5 = new int[population][student];
int[][] aMatrix6 = new int[population][student];

boolean found=false;
int count=0;
int asign=0;
int asign2=0;
int asign3=0;
int asign4=0;
int asign5=0;
int title2;
int asignOr2=0;
int asignOr3=0;
int asignOr4=0;
int asignOr5=0;
boolean found2=true;
boolean found3=true;
int index1=0;
int index2=0;
int add=0;
int answer=0;
int combine=0;
int total=0;

//store in new array for index 0

for(int gene=0;gene

//population
for(int Inipop=0;Inipop

else
{
for(int i=0;i

if(aMatrix2[chL1-(i+1)][0]!=aMatrix[chL1][0])
{
asignOr=aMatrix[chL1][0];
//asignment no
aMatrix2[chL1][0]=asignOr;
//value count fitness
aMatrix2[chL1][1]=1;
// print.println(aMatrix2[chL1-(i+1)][0]+" is not =="+aMatrix[chL1][0]);

}
else {

asignOr=aMatrix[chL1][1];
// print.println(aMatrix2[chL1-(i+1)][0]+"=="+aMatrix[chL1][0]);
// print.println("second choice "+asignOr);

for(int s=0;s

// print.println(aMatrix2[chL1-(s+1)][0]+" is not =="+asign2);
}
else
{
//found = true;
asign3=aMatrix[chL1][2];
// print.println(aMatrix2[chL1-(i+1)][0]+"=="+aMatrix[chL1][0]);
// print.println("third choice "+asign3);
for(int j=0;j

if(r!=aMatrix2[chL1-(ran+1)][0])
//print.println("random number masuklah");
aMatrix2[chL1][0]=r;
aMatrix2[chL1][1]=4;
}break;

}
}break;}

} break;
}

}

}

add=aMatrix2[chL1][1];
// print.println("priority value "+add);
combine=aMatrix2[chL1][0];

print.println((chL1+1)+ " get project no: "+aMatrix2[chL1][0]);
print.println(" ");
count ++;

//value add of priority in chromosome
fitness+=add;
aMatrix2[chL1][2]=fitness;
answer= aMatrix3[chL1][0];
Cfit +=" "+aMatrix2[chL1][0];

//store assignment
aMatrix5[Inipop][chL1]= aMatrix2[chL1][0];
//store priority
aMatrix6[Inipop][chL1]= aMatrix2[chL1][1];
// print.println("priority value "+ aMatrix6[Inipop][chL1] );
}
print.println("kumpulkan "+Cfit);
//store
aMatrix4[Inipop][0]= Cfit ;
print.println(" fitness "+Inipop+": "+fitness);
aMatrix3[Inipop][0]=fitness;
// print.println("jawapan fitness..... "+ aMatrix3[Inipop][0]);
print.println("");
print.println("");

}

/********************Binary tournament********************/
/*************** 1st random number of choosen value**********************************************************/
int randomCv;
int nV=0;
int indexR;
String radomVal="";
int tempVal;
String tempRAn;
int valueR=0;
boolean ran1=false;
boolean ran2=false;
int randomvalue1[]=new int[10];//store value random1
int randomvalue2[]=new int[10];//store value random2

int min1=aMatrix3[0][0];
int min2=aMatrix3[0][0];

randomCv=generator.nextInt(population);
print.println("random Value : "+ randomCv);

if (randomCv>=2)
{
for (int randomLoop=0;randomLoop

indexR=generator.nextInt(population-1);
tempVal=aMatrix3[indexR][0];
// value=Integer.parseInt(tempVal,2);
radomVal+= "\t"+tempVal;
print.println("jawapan storage 2: "+tempVal);
for(int minSearch=0;minSearch<>=aMatrix3[minSearch][0])
{
min2=min1;
min1=aMatrix3[minSearch][0];
index2=index1;
index1=minSearch;

}
else if(min1>=aMatrix3[minSearch][0])
{
min2=aMatrix3[minSearch][0];
index2=minSearch;

}

}

}

print.println( " ");
print.println("minimum 1: "+min1);
print.println("index1: "+(index1));
print.println("minimum 2: "+(min2));
print.println("index2: "+ (index2));
// print.println("\n");
// print.println("\n");
}

else
{ran1=true;
String buz = "no random value";
print.println(buz);
print.println("\n");
}

/********************call cromosome choosen*******************************/
if(ran1==false)
{
int save=0;
int[] array1 = new int [student];//array isi chromose1 yang terpilih max1
int[] array2 = new int [student];//array isi chromose2 yang terpilih max2
int[] array3 = new int [student];
int[] array4 = new int [student];

print.println("_______________________________________________________________________________________________________________________________________");
print.println("Population "+" "+" Chromosome "+"\t"+"\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "fitness ");
print.println("_______________________________________________________________________________________________________________________________________");
for(int call=0;call

// save=aMatrix2[call1][0];

print.print(" "+ aMatrix4[call][0]);

print.print("\t"+"\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+"\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ aMatrix3[call][0]);
print.println("");
}
print.println("_________________________________________________________________________________________________________________________________");

//chromosome the most minimum and 2nd minimum in population
//first index
//index 1(chromosome)
print.print(" chromosome index1 ");

for(int mini=0;mini

for(int min=0;min

print.print(aMatrix5[mini][min]+" ");
array1[min]=aMatrix5[mini][min];

}

}

}

//proirity index 1
for(int mini=0;mini

for(int min=0;min

//print.print(aMatrix6[mini][min]+" ");
array3[min]=aMatrix6[mini][min];

}

}

}

print.println(" ");

//index 2 (chromosome)
print.print(" chromosome index2 ");

for(int mini=0;mini

for(int min=0;min

print.print(aMatrix5[mini][min]+" ");
array2[min]=aMatrix5[mini][min];
}

}

}

//proirity index 2
for(int mini=0;mini

for(int min=0;min

//print.print(aMatrix6[mini][min]+" ");
array4[min]=aMatrix6[mini][min];

}

}

}

/****************************************************************UNIFORM CROSSOVER*************************************************/

Random y = new Random();

print.println("");

int [] ans = new int [student];//panjang allele 123456
int q=0;
int [] priority = new int [student];
for(int r= 0;r

print.println("");
print.println("");
/**************************************************MUTATION SWAPPING (PENIPU)********************************************************/
int loc1 =0;
int loc2=0;
int loc11 =0;
int loc22=0;
double ran = Math.random();
if(ran <0.9) loc1 =" y.nextInt(8);" loc2 =" y.nextInt(8);" loc1 ="="" temp1=" ans[loc1];" temp2 =" ans[loc2];" temp3 =" temp1;" temp11=" ans[loc11];" temp22 =" ans[loc22];" temp33 =" temp11;" t =" 0;t

}
print.println("");
print.println(" fitness after mutation: "+addfit);
System.out.println(addfit+" ");
total+=addfit;
}
print.println(" " );

}
int ave;
ave=total/generation;

print.println(" Average "+ave );

}//close try

catch(FileNotFoundException fnf)
{
System.out.println("File Not Found");
System.out.println(fnf.getMessage());
}
catch(IOException io)
{
System.out.println(io.getMessage());
}

catch(Exception a)
{
}

print.close();
}//close main
}//close minipro

sometime it juz suckssss

i tried my hard maintain a friends relationship, but some time it seems i work 4 nothing.... tried to ignore even sometime fell it sakit ati. but still have my limit to face with tht. dah la dah malas lah... lantak la. dah penat la...suke ati korang la.... do wht ever u wat to...

juz go ahead. malas dah aku nak tanyer...nak keep on contect... lyn jer saper yg nak kwn ngn kiter... malas dah nak tehegeh2 mcm muke x tau malu.... penat la... dah penat. may be i have done something wrog be 4 this. so take this chances to ask for forgiveness from u all.

so moralnyer aku dapat kali ni... 'hurm don't know wht to say la'. juz ikut flow sudah la. malas nak nak buat bender sia2. juz waste time. pas 2 some more buat sakit ati.

adam rafique



cyber cafe (_prolog)

% =====================KNOWLEDGE BASE==============================

% dynamic variables
:-dynamic(pc_member/2).
:-dynamic(pc_list/4).

% list of people registered as member. pc_member(ID,Name)
pc_member(110,ali).
pc_member(112,abdul).
pc_member(115,salmah).
pc_member(111,farah).
pc_member(118,siti).

% list of pc (all). pc_list(PcNum,Username,Usertype,Starttime)
pc_list(1,null,null,0).
pc_list(2,ali,member,2007).
pc_list(3,farah,member,1100).
pc_list(4,null,null,0).
pc_list(5,aminah,nonmember,0900).
pc_list(6,null,null,0).
pc_list(7,null,null,0).
pc_list(8,samad,nonmember,1434).

%pc_ava(X):- pc_list(X,null,_,_).

pc_available(L):-
findall(X,pc_list(X,null,_,_),L).

all_pc(L):-
findall(X,pc_list(X,_,_,_),L).

% =========================PROGRAMME===============================

% the program
run:-
greetings.

% ========================MAIN MENU================================

% main menu
greetings:-

nl,nl,
write('+---------------------------+'),nl,
write('| Epc-shop cybercafe Center |'),nl,
write('+---------------------------+'),nl,nl,
write(' Main Menu '),nl,
write(' -----------'),nl,
write(' 1 . PC Menu '),nl,
write(' 2 . Member Menu '),nl,
write(' 3 . Payment Menu '),nl,
write(' 4 . Terminate Program '),nl,nl,
write('Enter your selection : '),
read(X),
mainmenu(X).

% =======================PC MENU==================================

% pc menu
mainmenu(1):-
nl,nl,
write(' PC Menu '),nl,
write(' -------'),nl,
write(' 1 . View list of all pc '),nl,
write(' 2 . Register to use '),nl,
write(' 3 . Back to Main menu '),nl,nl,
write('Enter your selection : '),
read(X),
pcmenu(X).

% pc listing all.
pcmenu(1):-

write('+------------------------------------------------------+'),nl,
write('| PC NO | Name | Type | Start at |'),nl,
write('+------------------------------------------------------+'),nl,
listing(pc_list),nl,

mainmenu(1).

% pc listing all.
pcmenu(2):-
write('Enter pc number : '),read(W),nl,
write('Enter Name : '),read(X),nl,
write('Enter User Type : '),read(Y),nl,
write('Enter Start time (24-hours format): '),read(Z),nl,
retract(pc_list(W,_,_,_)),
assert(pc_list(W,X,Y,Z)),
write('PC loaded! : '),nl,
mainmenu(1).

% =======================MEMBER MENU================================

% member menu
mainmenu(2):-
nl,nl,
write(' Member Menu '),nl,
write(' -----------'),nl,
write(' 1 . View list of registered members '),nl,
write(' 2 . Search existing member '),nl,
write(' 3 . New member registration '),nl,
write(' 4 . Back to Main menu '),nl,nl,
write('Enter your selection : '),
read(X),
membermenu(X).

% member listing.
membermenu(1):-
write('+----------------------------------------------+'),nl,
write('| ID | Name |'),nl,
write('+----------------------------------------------+'),nl,
listing(pc_member),nl,
mainmenu(2).

% searching existing member.
membermenu(2):-
nl,nl,
write(' Searching Menu '),nl,
write(' --------------'),nl,
write(' 1 . By ID '),nl,
write(' 2 . By Name '),nl,
write(' 3 . Back '),nl,nl,
write('Enter your selection : '),
read(X),
searchmenu(X).

% search existing member by ID.
searchmenu(1):-
write('Enter member''s ID : '),
read(Z),
searching(Z).

searching(Z):-
pc_member(X,Y),nl,
Z=:=X,
write('Member information are :'),
write('ID: '),write(X),nl,
write('Name: '),write(Y),nl,
membermenu(2).

searching(Z):-
pc_member(X,Y),
Z=\=X,
write('Member not exist! :'),
membermenu(2),!.

% search existing member by name.
searchmenu(2):-
write('Enter member''s Name: '),
read(M),
searching2(M).

searching2(M):-
pc_member(X,Y),nl,
M=:=Y,
write('Member information are : '),
write('ID: '),write(X),nl,
write('Name: '),write(Y),nl,
membermenu(2).

searching2(M):-
pc_member(X,Y),
Z=\=Y,
write('Member not exist! :'),
membermenu(2),!.

%register new member
membermenu(3):-
write('Enter your name : '),
read(X),nl,
write('Enter your secret id : '),
read(K),nl,
assert(pc_member(X,K)),
write('Successfully add!'),nl,
mainmenu(2).

% ======================PAYMENT MENU================================

% payment menu
mainmenu(3):-
nl,nl,
write('List of available pc: '),nl,
write('+------------------------------------------------------+'),nl,
write('| PC NO | Name | Type | Start at |'),nl,
write('+------------------------------------------------------+'),nl,
listing(pc_list),nl,nl,
write('Enter pc number : '),read(W),nl,
pc_list(A,B,C,D),
W =:= A,
write('pc number : '),write(A),nl,
write('Customer Name : '),write(B),nl,
memberstatus(C,D).

% if PC not in use
memberstatus(null,0):-
write('PC not being use!'),nl,
greetings,!.

% for member PC usage
memberstatus(member,D):-
write('Enter current time (24-hours format) : '),read(X),nl,
Time is X-D,
Time2 is D/60,
Time3 is (Time2*2*0.9),
write('Status : '),write('member'),nl,
write('Start using pc at : '),write(D),nl,
write('End using pc at : '),write(X),nl,
write('Total time using : '),write(Time2),write(' hour'),nl,
write('Total payment is : RM'),write(Time3),nl,

total(1,Time3).

total(1,Time3):-

write('RM: '),write(Time3),

greetings.

% for non member PC usage
memberstatus(nonmember,D):-
write('Enter current time (24-hours format) : '),read(X),nl,
Time is X-D,
Time2 is D/60,
Time3 is (Time2*2),
write('Status : '),write('nonmember'),nl,
write('Start using pc at : '),write(D),nl,
write('End using pc at : '),write(X),nl,
write('Total time using : '),write(Time2),write(' hour'),nl,
write('Total payment is : RM'),write(Time3),nl,
greetings.

% ====================ERROR HANDLING===============================

% back to previous menu
membermenu(4):- greetings,!.
pcmenu(3):- greetings,!.
searchmenu(3):- mainmenu(2),!.

% to exit the program
mainmenu(4):-
nl,write('Exiting program..thank you'),nl,!.

% invalid data input
mainmenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
greetings,!.
membermenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
mainmenu(2),!.
searchmenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
membermenu(2),!.
pcmenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
mainmenu(1),!.