package LPP_Models; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Scanner; import java.util.concurrent.TimeUnit; import ilog.concert.IloException; import ilog.concert.IloIntVar; import ilog.concert.IloLinearNumExpr; import ilog.concert.IloNumVar; import ilog.cplex.IloCplex; import java.util.Random; public class LPP_PARTICULAR_CASE{ static int slots; static int items; static double demand[]; static double demand_2[]; static double demand_3[]; static double demand_4[]; static double demand_6[]; static double demand_8[]; static double demand2[]; static int setup_cost; static int runs; static double epsilon; static double waste; static double num_print; static double total_demand; static double cluster_demand; static double current_demand[]; static double current_demand2[]; static int item_list[]; static int item_list2[]; static int item_list3[]; static int item_list4[]; static double y_i[]; static double y[]; static double rate[]; static double rate2[]; static double toplam_y_i; static int toplam_y; static double temp_max; static int temp_index; static double quantity_1[]; static double slot_1[]; static double quantity_2[]; static double slot_2[]; static double min; static double remaining_demand[]; static double remaining_demand2[]; static int assign_slot[][]; static int assign_slot_2[][]; static int assign_slot2[][]; static int assign_slot_3[][]; static int assign_slot_4[][]; static int assign_slot_5[][]; static int assign_slot_6[][]; static int sum_slot; static double max_quantity; static double divide[][]; static double item_temp_demand[][]; static double item_temp_demand2[][]; static double item_temp_demand_2[][]; static double item_temp_demand_3[][]; static double temp_dem[][]; static int item_num_slot[][]; static int item_num_slot2[][]; static int item_temp[][]; static int item_temp2[][]; static double temp_dem_2[][]; static int run_order[][]; static int run_order2[][]; static int run_order_2[][]; static int run_order_3[][]; static int run_order_4[][]; static int run_order_5[][]; static int runn_order[][]; static int run_items[]; static int run_items_2[]; static int run_items_3[]; static int run_items_4[]; static int run_items_5[]; static int runn_items[]; static int dizi[]; static int dizi2[]; static int dizi3[]; static int dizi4[]; static int Slots_[]; static int num_it[]; static int num2_it[]; static int num_it_slot; static int toplam_num_it; static int toplam_num2_it; static int kalan_num_it; static int item_order[]; static int item2_order[][]; static int item3_order[][]; static int item4_order[][]; static int temp_length[]; static int temp2_length[]; static int temp3_length[]; static int Temp_[]; static int Temps_[]; static double length_run[]; static double length_run2[]; static double cluster_length_run[][]; static double cluster_solution[]; static int cluster_assign_slot[][][]; static double total_run_2; static double Best_Length_run[]; static double Best_Length_run2[]; static double percentage[]; static int run_sayisi[]; static int max_ij [][]; static int max2_ij [][]; static int min2_ij [][]; static double ratio_; static int min_ij [][]; static int cluster_length; static int cluster[]; static int clus_length[][]; static int no_Iter_runs[]; static int cluster_items[][][]; static int runs_2; static int cluster_length2; static int cluster2[]; static int clus_length2[][]; static int no_Iter_runs2[]; static int cluster_items2[][][]; static int runs_3; static int start_cluster; static int start_cluster2; static int iter_cluster[]; static int item_in_list[]; static int item_in_list2[]; static int total_CLUST; static int tot_CLUST; static int tot_CLUSTs; static double B_run[]; static double abs; static int no_Iter; static int total_clusters; static int v_ij[][]; static int v_ij_2[][]; static int S_j[]; static int S_[]; static double B_j[]; static int v_ij_assign_slot[][]; static int v_ij_assign_slot2[][]; static double Solution; static double demand4[]; static int toplam2_y_i; static int y2_i[]; static double[][] divide2; static int tot_cluster2; static int tot_cluster3; static int clus_run_items[]; static int z_ij[][]; static int run_num[]; static double total_demand3; static String[] str= new String[1000]; static int sum_clust; static double temp; static int ExraLength; static int Extraslots; static double L_U[]; static double L_B[]; static double cost_length; static double cost_temp; static double totall_cost; static double total_cost; static int mos[]; static int mos_[]; static double item_waste[]; static double obj_value[]; static double Best_Costss; static double BestSolution; static int improve2; static int kacinci_iter; static int kacinci_iter2; public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException { Scanner input2 = new Scanner(new File("LPP_PARTICULAR_CASE_INSTANCES.txt")); int sss=100000; int sor=0; int sor1=0; int sor2=0; double Sols=0; temp=0; int kss=0; totall_cost=90000000; total_cost=0; improve2=-1; double Bestt_Solution=9000000; int fls=157; for(int a=1; a temp_max){ temp_max = demand_8[j]; temp_max_index = j; item_order[i]=j; } } double swap = demand_8[i]; demand_8[i] = demand_8[temp_max_index]; demand_8[temp_max_index] = swap; int swap2 = dizi[i]; dizi[i] = dizi[temp_max_index]; dizi[temp_max_index] = swap2; int swap3 = dizi[i]; dizi[i] = dizi[temp_max_index]; dizi[temp_max_index] = swap2; } double item=items; double slot=slots; temp=(int) Math.ceil((item/slot)); for(int j=1; j=slots*(runs-j+1)) { Temp_[j]++; Temps_[j]=0; for(int i=slots*(j-1)+1; i temp_max_2){ temp_max_2 = S_j[j]; temp_max_index_2 = j; item_order[i]=j; } } int swap = S_j[i]; S_j[i] = S_j[temp_max_index_2]; S_j[temp_max_index_2] = swap; int swap2 = dizi[i]; dizi[i] = dizi[temp_max_index_2]; dizi[temp_max_index_2] = swap2; } double total_L_B=0; int sln=50000; int slnm=0; int step=0; int heru=0; int slots_=slots; for(int i=1; i(slots*(runs-t)) && t!=runs) { t--; srcd=1; } if(srcd==0) { sls3+=num_it[t]; toplam_num2_it+=num_it[t]-1; if(t==runs) { if(toplam_num2_it0) { cluster_length = (int) 10+random2.nextInt(cluster_length2-9); } else { cluster_length = items-(start_cluster); } if(cluster_length==items) { cluster_length=items-5;; } if(cluster_length>items-(start_cluster)) { cluster_length=items-(start_cluster); } if(cluster_length>slots || cluster_length<1 ) { cluster_length = (int) 1+random2.nextInt(slots); } cluster_length = num_it[slsk]; int list=0; int cnt=0; for(int i=1; i temp_max3){ temp_max3 = current_demand2[jn]; temp_max_index3 = jn; } } double swaps2 = current_demand2[i]; current_demand2[i] = current_demand2[temp_max_index3]; current_demand2[temp_max_index3] = swaps2; int swap2 = dizi2[i]; dizi2[i] = dizi2[temp_max_index3]; dizi2[temp_max_index3] = swap2; } for(int i=1; i0){ y_i[cluster[i]]=1; } } toplam_y_i=0; for(int i=1; i=temp_max) { temp_max=rate[cluster[i]]; temp_index=cluster[i]; } } y_i[temp_index]+=1; toplam_y_i=0; for(int i=1; imax_quantity){ max_quantity=quantity_1[cluster[i]]; } } for(int j=1; j<1+1; j++) { tot_CLUST++; B_run[tot_CLUST]=max_quantity; for(int i=1; i0.5) { v_ij[i][tot_CLUST]=1; } } } } } total_CLUST=tot_CLUST; total_clusters = total_CLUST; int sps=0; try { IloCplex cplex = new IloCplex(); cplex.setParam(IloCplex.DoubleParam.TiLim, 500); IloNumVar[] standart = new IloNumVar[total_clusters+10]; standart = cplex.boolVarArray(total_clusters+10); IloIntVar[] standart_int = new IloIntVar[total_clusters+10]; standart_int= cplex.intVarArray(total_clusters+10,0,(int) Double.MAX_VALUE); IloNumVar[] y = new IloNumVar[total_clusters+10]; y= cplex.boolVarArray(total_clusters+10); IloLinearNumExpr objective= cplex.linearNumExpr(); for(int j=1; j0.9) { SPP_Length+=B_run[j]; num_print_ilk+=B_run[j]; } } double SPP_Cost = cplex.getObjValue(); double SPP1_COST=SPP_Cost; Solution=cplex.getObjValue(); int ysc=0; SPP_Length=0; for(int j=1; j0.9) { ys++; ysc++; SPP_Length+=B_run[j]; for(int i=1; i0.5) { v_ij_assign_slot[i][j]=assign_slot_5[i][j]; assign_slot[i][j]=assign_slot_5[i][j]; clus_run_items[j]++; } } } for(int j=1; j0.5) { } } } } cplex.end() ; } catch (IloException e) { System.err.println("Concert exception '" + e + "' caught"); } double waste_7 = (((Solution*slots)- total_demand)/total_demand); printWriter.close (); BestSolution=Solution; BestSolutions=Solution; for(int i=1; i temp_max_2){ temp_max_2 = S_j[j]; temp_max_index_2 = j; item_order[i]=j; } } int swap = S_j[i]; S_j[i] = S_j[temp_max_index_2]; S_j[temp_max_index_2] = swap; int swap2 = dizi3[i]; dizi3[i] = dizi3[temp_max_index_2]; dizi3[temp_max_index_2] = swap2; } for(int j=1; j1; h-- ) { sum=sum+L_B[dizi3[h]]; if(Math.floor(sum/(j-h+1))<=L_B[dizi3[h-1]]) { if(L_U[dizi3[j]]>sum/(j-h+1)) { L_U[dizi3[j]]=Math.min(Math.floor(sum/(j-h+1)), L_U[dizi3[j]]); h=0; } } } } for(int j=2; jMath.ceil(demand_6[i]/L_B[dizi3[j]])) { max2_ij[i][dizi3[j]]=(int) Math.ceil(demand_6[i]/L_B[dizi3[j]]); } if(max2_ij[i][dizi3[j]]>slots) { max2_ij[i][dizi3[j]]=slots; } } } for(int i=1; i0 ) { min_ij[ik][e]=assign_slot[ik][e]-5; max_ij[ik][e]=assign_slot[ik][e]+5; min_ij[ik][f]=assign_slot[ik][f]-5; max_ij[ik][f]=assign_slot[ik][f]+5; if(min_ij[ik][e]<0) { min_ij[ik][e]=0; } if(max_ij[ik][e]>max2_ij[ik][e]) { max_ij[ik][e]=max2_ij[ik][e]; } if(min_ij[ik][f]<0) { min_ij[ik][f]=0; } if(max_ij[ik][f]>max2_ij[ik][f]) { max_ij[ik][f]=max2_ij[ik][f]; } } } if( jo==f) { if( assign_slot[ik][f]>0 ) { min_ij[ik][f]=assign_slot[ik][f]-5; max_ij[ik][f]=assign_slot[ik][f]+5; min_ij[ik][e]=assign_slot[ik][e]-5; max_ij[ik][e]=assign_slot[ik][e]+5; if(min_ij[ik][e]<0) { min_ij[ik][e]=0; } if(max_ij[ik][e]>max2_ij[ik][e]) { max_ij[ik][e]=max2_ij[ik][e]; } if(min_ij[ik][f]<0) { min_ij[ik][f]=0; } if(max_ij[ik][f]>max2_ij[ik][f]) { max_ij[ik][f]=max2_ij[ik][f]; } } } if(jo!=e && jo!=f ) { min_ij[ik][jo]=assign_slot[ik][jo]; max_ij[ik][jo]=assign_slot[ik][jo]; } } } try { IloCplex cplex = new IloCplex(); cplex.setParam(IloCplex.DoubleParam.TiLim, 100); IloNumVar[][][] xijk = new IloNumVar[items+1][runs+1][]; for (int i5 = 0; i5 < items+1; i5++) { for (int j = 0; j < runs+1; j++) { xijk[i5][j] = cplex.boolVarArray(slots+1); } } IloIntVar[][][] qijk = new IloIntVar[items+1][runs+1][]; for (int i5 = 0; i5 < items+1; i5++) { for (int j = 0; j < runs+1; j++) { qijk[i5][j] = cplex.intVarArray(slots+1,0,(int) Double.MAX_VALUE); } } IloNumVar[][] y_ij = new IloNumVar[items+1][]; for (int i5 = 0; i5 < items+1; i5++) { y_ij[i5] = cplex.boolVarArray(runs+1); } IloIntVar[] Lj = new IloIntVar[runs+1]; Lj= cplex.intVarArray(runs+1,0,(int) Double.MAX_VALUE);; IloLinearNumExpr objective= cplex.linearNumExpr(); for (int j=1; j < runs+1; j++) { objective.addTerm(Lj[j], 1); } cplex.addMinimize(objective); for (int i5=1; i5 < items+1; i5++) { IloLinearNumExpr o= cplex.linearNumExpr(); for (int j = 1; j < runs+1; j++) { for (int k = min_ij[i5][j]; k0.9) { assign_slot[i1][j]=k; } } } } if(cplex.getObjValue()0) { for(int k=1; k=0.6*items) { num1=4+random.nextInt(4); } } if(items<=15 && items>10) { num1=5+random.nextInt(5); } if(items<=20 && items>15) { num1=5+random.nextInt(5); } if(items<=25 && items>20) { num1=5+random.nextInt(5); } if(items<=100 && items>25) { num1=5+random.nextInt(5); } int list=0; for(int i=1; imax2_ij[i][j]) { max_ij[i][j]=max2_ij[i][j]; } } } else { for(int j=1; j0.9) { assign_slot[i1][j]=k; } } } } if(cplex.getObjValue()0) { for(int k=1; k