#include #include #include #include "aloca.h" #include "sbd.h" #include "gls.h" #include "sb.h" #include "sbtools.h" #include "rglsk.h" /* * */ SB_RGLSk( long MY_RUN , long *which_job, double *SB_RGLSk_bound , double *SB_RGLSk_cpu , long number_of_times , long *LB , long *my_seq_machines , long m , long my_jobs , long finishing , long *macsucc , long *macpred , long *jobsucc , long *jobpred , long *which_machine , long oper , long depthnew , long maxdepth , long *machine_sched , long *actrelease , long *releases , long *tails , long *moddeadline , long *actdeadline , long *processing_time , long *operations , long *pdc , long *scs , long *LIST , long *POS , long *position , long *machine_total , long deadlines , long *Upper_Bound , long *introd , long *bottleneck_order , long *lateness ) { long i , i2 , j2 ; long kk ; long mksp ; long theta ; long deleted_machine ; long number_of_deleted_machines ; long solution_number ; long kl ; long MKSP_GUESS ; long FEASIBILITY_MODE ; long SELECTED ; long j ; long tphase_I ; long sphase_I ; long sphase_II ; long sequenced_machines ; long machines_sbgls2 ; long im ; double y ; double aa , bb , tweight ; double cweight , cbefore ; long flag ; double *weights ; long *the_order ; long *feasible_problems ; long *labelled_list ; double *SB_GLS1_bound ; double *SB_GLS1_cpu ; double *SB_GLS2_bound ; double *SB_GLS2_cpu ; long LONGEST_PATH() ; double random_number() ; /* STARTTIME(6) ; */ MKSP_GUESS = ((long) RAND_MAXI) ; tphase_I = 0 ; sphase_I = 0 ; sphase_II = 0 ; number_of_times = 10 ; // printf("Run RGLSk %ld times \n",number_of_times) ; flag = alocd(&weights,MAXMACHINES) * aloci(&labelled_list,MAXOPER) * aloci(&feasible_problems,MAXRUNS) * aloci(&the_order,MAXMACHINES) * alocd(&SB_GLS1_bound,MAXRUNS) * alocd(&SB_GLS1_cpu,MAXRUNS) * alocd(&SB_GLS2_bound,MAXRUNS) * alocd(&SB_GLS2_cpu,MAXRUNS) ; if (deadlines) { FEASIBILITY_MODE = 1 ; } else { FEASIBILITY_MODE = 0 ; } for (im=0 ; im< number_of_times; im++) { for (i2=1;i2<=m;i2++) introd [i2] = best_intro [ i2 ] ; sequenced_machines = *my_seq_machines ; // for (i=1 ;i<= sequenced_machines;i++) printf("%ld ",introd[i]) ; // printf("\n") ; /* * restore the current best upper bound */ kk = 0 ; for (i2=1;i2<=m;i2++) { for (j2=1;j2<=machine_total[i2];j2++) { machine_operations[i2][j2] = BEST_SCHEDULE_global [ kk ] ; kk++ ; } } SEQUENCE_FIXED_MACHINES(machine_sched, machine_total, position, m, finishing, macpred, macsucc) ; mksp = LONGEST_PATH(m, my_jobs, oper, finishing, jobpred, jobsucc, macpred, macsucc, MKSP_GUESS, machine_sched, actrelease, releases, tails, moddeadline, actdeadline, processing_time, operations, pdc, scs, LIST, POS, machine_total, labelled_list, 0) ; // printf("RGLSk: Current UB is %ld \n",mksp) ; number_of_deleted_machines = ((long) (sqrt ((double) m))) ; // printf(" Machines to delete :") ; for (kl=1;kl<=number_of_deleted_machines;kl++) { for (i=1;i<=sequenced_machines;i++) { the_order[i] = i ; } solution_number = sequenced_machines ; aa = 1.0 ; bb = 1.0 ; for (i=1;i<=solution_number;i++) { j = the_order[i] ; aa = 2.0 * aa ; bb = 3.0 * bb ; weights[j] = (aa / bb) ; } tweight = 0.0 ; for (i=1;i<=solution_number;i++) tweight = tweight + weights[i] ; for (i=1;i<=solution_number;i++) { j = the_order[i] ; weights[j] = (weights[j] / tweight) ; } tweight = 0.0 ; for (i=1;i<=solution_number;i++) tweight = tweight + weights[i] ; /* num = rand() ; y = num / RAND_MAX ; */ y = random_number() ; y = y * tweight ; cweight = 0.0 ; SELECTED = 0 ; for (i=1;i<=solution_number;i++) { cbefore = cweight ; cweight = cweight + weights[i] ; if ((cbefore <= y) && (y <= cweight)) { SELECTED = i ; i = solution_number + 100 ; } } if (SELECTED == 0) { printf("Error in randomized machine deletion , y = %f , tweight = %f \n",y,tweight) ; exit(1) ; } deleted_machine = introd [SELECTED] ; // printf("%ld- ",deleted_machine) ; DELETE_MACHINE(deleted_machine, machine_sched, pdc, scs, machine_total, finishing, macpred, macsucc) ; mksp = LONGEST_PATH(m, my_jobs, oper, finishing, jobpred, jobsucc, macpred, macsucc, MKSP_GUESS, machine_sched, actrelease, releases, tails, moddeadline, actdeadline, processing_time, operations, pdc, scs, LIST, POS, machine_total, labelled_list, 0); for (i=SELECTED;i<=sequenced_machines;i++) { introd [i] = introd [i+1] ; } sequenced_machines-- ; } // printf("\n") ; /* for (i=1 ;i<= sequenced_machines;i++) printf("%ld ",introd[i]) ; printf("\n") ; */ theta = (((long) (log(((double) (sequenced_machines*my_jobs)))))+1) ; FEASIBILITY_MODE = 0 ; if (sequenced_machines > 1) { GLS(m, my_jobs, finishing, oper, macpred, macsucc, jobpred, jobsucc, theta, MKSP_GUESS, sequenced_machines, depthnew, maxdepth, LB, machine_sched, actrelease, releases, tails, moddeadline, actdeadline, processing_time, operations, pdc, scs, LIST, POS, machine_total, position, which_machine, FEASIBILITY_MODE, 1) ; } *my_seq_machines = sequenced_machines ; *Upper_Bound = ((long) RAND_MAXI); *lateness = ((long) RAND_MAXI) ; SB_GLS1(which_job, im, feasible_problems, SB_GLS1_bound, SB_GLS1_cpu, LB, my_seq_machines, m, my_jobs, finishing, macsucc, macpred, jobsucc, jobpred, which_machine, oper, &tphase_I, &sphase_I, &sphase_II, depthnew, maxdepth, machine_sched, actrelease, releases, tails, moddeadline, actdeadline, processing_time, operations, pdc, scs, LIST, POS, position, machine_total, deadlines, Upper_Bound, introd, bottleneck_order, lateness) ; machines_sbgls2 = *my_seq_machines ; /* for (i=1 ;i<= machines_sbgls2;i++) printf("%ld ",introd[i]) ; printf("\n") ; */ /* SB_GLS2(im, which_job, SB_GLS2_bound, SB_GLS2_cpu, LB, m, my_jobs, finishing, macsucc, macpred, jobsucc, jobpred, which_machine, oper, &tphase_I, &sphase_I, &sphase_II, depthnew, maxdepth, machine_sched, actrelease, releases, tails, moddeadline, actdeadline, processing_time, operations, pdc, scs, LIST, POS, position, machine_total, deadlines, Upper_Bound, machines_sbgls2, introd, bottleneck_order, lateness) ; */ } /* STOPTIME(6) ; */ printf("%ld, Solution found from SB_RGLSk : %ld Lower bound : %ld \n", MY_RUN,BESTGMAKESPAN,*LB) ; if (deadlines) { printf("Maximum Lateness = %ld \n",BESTGLATENESS) ; } /* printf("CPU time for SBP = %f\n",(((double) USERTIME(6)) / 1000.0)) ; */ SB_RGLSk_bound [ MY_RUN ] = ((double) UB_global) ; /* SB_RGLSk_cpu [ MY_RUN ] = (((double) USERTIME(6)) / 1000.0) ; */ free((char *) weights) ; free((char *) labelled_list) ; free((char *) feasible_problems) ; free((char *) the_order) ; free((char *) SB_GLS1_bound) ; free((char *) SB_GLS1_cpu) ; free((char *) SB_GLS2_bound) ; free((char *) SB_GLS2_cpu) ; }