Assignment Problem
Problem Definition :
There are n people who need to be assigned to execute n jobs, one person per job.
The cost of assigning the ith person to the jth job is a known quantity C[i,j] for each pair i,j=1, … , n.
Problem is to find an assignment with smallest total cost !
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
public class Assignment {
static int o;
static int i;
static int a;
static int s;
public static void main(String args[])
{
ArrayList<Integer> dizi = new ArrayList<Integer>();
int[] onur = {9,2,7,8};
int[] iso = {6,4,3,7};
int[] anil = {5,8,1,8};
int[] selim = {7,6,9,4};
Random r = new Random();
Assignment ass = new Assignment();
for(int k=0;k<10000000;k++)
{
ass.o = r.nextInt(4);
do{
ass.i = r.nextInt(4);
}while(ass.i == ass.o);
do{
ass.a = r.nextInt(4);
}while(ass.a == ass.o || ass.a ==ass.i);
do{
ass.s = r.nextInt(4);
}while((ass.s == ass.o) || (ass.s == ass.i) || (ass.s == ass.a));
if(!dizi.contains(onur[ass.o] + iso[ass.i] + anil[ass.a] + selim[ass.s]))
{
dizi.add(onur[ass.o] + iso[ass.i] + anil[ass.a] + selim[ass.s]);
}
}
System.out.println(dizi);
Comparator c = Collections.reverseOrder();
Collections.sort(dizi,c);
System.out.println("Minumum cost 1/10000000 ihtimalle hatalı olmak şartıyla : " +dizi.get(dizi.size()-1));
}
}
Hiç yorum yok:
Yorum Gönder