/* ********************************************************** * * * This program is the implementation of the shifting * * bottleneck algorithm for the job shop scheduling * * problem with deadlines * * * ********************************************************** */ /* * here define variables for DEBUGGING, TEST SETS * STATISTICS #define ALL_RESULTS * collect different statistics regarding criticality of * machines #define TEST_PATHS * GLS mode, TABU_MODE is also available */ #define GLS_MODE /* * Test CARLIER and PINSON's fixing. */ /* #define FIXING_WANTED */ #include #include #include #include #include //#include "time.h" #include "read.h" #include "sbtools.h" #include "sbd.h" #include "sodl.h" #include "longest.h" #include "rglsk.h" #include "sb.h" #include "active.h" #include "gls.h" #include "random.h" #include "aloca.h" /****/ #define _twTime 1 /****/ #define theNorm(a,b) (setup_onemachine[a][b]) /****/ #include "solver.h" /****/ main(argc,argv) long argc ; char *argv[] ; { long i , k , j ; long number_of_runs ; long kk , b1 , b2 ; long sequenced_machines ; long max_iter ; long mksp ; long MKSP_GUESS ; long jj ; long MULT , my_total ; long total_problems ; long tphase_I ; long sphase_I ; long sphase_II ; long realtasks ; long deadlines ; long depthnew ; long maxdepth ; long m ; long my_jobs ; long oper ; long finishing ; long LB ; long my_seq_machines ; long lateness ; long Upper_Bound ; long best_lb ; long best_upper_bound ; long run_it ; long flag ; long TOTRUNS ; double Average_Sola ; double Best_Sola ; double Worst_Sola ; double start1 , start2 , start3 ; double alpha , alphad ; double tcp ; /* MAXMACHINES */ long *machine_total ; long *machine_sched ; long *introd ; long *bottleneck_order ; /* MAXOPER */ long *stored_machine ; long *labelled_list ; long *which_job ; long *actrelease ; long *releases ; long *tails ; long *moddeadline ; long *actdeadline ; long *processing_time ; long *operations ; long *pdc ; long *scs ; long *LIST ; long *POS ; long *which_machine ; long *jobpred ; long *jobsucc ; long *macpred ; long *macsucc ; long *position ; /* MAXRUNS */ long *feasible_problems ; long *solut ; double *best_gap_gls ; double *cpu_gls ; double *SB_GLS1_bound ; double *SB_GLS2_bound ; double *SB_RGLSk_bound ; double *SB_GLS1_gap ; double *SB_GLS2_gap ; double *SB_RGLSk_gap ; double *SB_GLS1_cpu ; double *SB_GLS2_cpu ; double *SB_RGLSk_cpu ; double *SB_GLS1_tcpu ; double *SB_GLS2_tcpu ; double *SB_RGLSk_tcpu ; double *total_cpu ; double *Average_Sol ; double *Best_Sol ; double *Worst_Sol ; double *tgap ; double total_time ; if (argc!=2) {fprintf(stderr,"program requires one argument (filename)\n");exit(1);} GetAuxgraph(mymaxK,MAXJOBS,MAXJOBS,1); /****/ SETUPNUMBER = 1; //atoi(argv[1]) ; //qqq deadlines = 1 ; total_problems = 60; test_strategy = 1 ; if (test_strategy == -8) { lamda2 = ((double) (atoi(argv[2]))) ; lamda1 = ((double) (atoi(argv[3]))) ; } MULT = 4 ; KAPPA = 5 ; rndi = 0 ; input_file = fopen(argv[1],"r") ; //qqq fscanf(input_file,"%d",&total_problems); //qqq /* if (test_strategy != -8) { printf("I use kappa %ld \n",KAPPA) ; printf("I use multiplier %ld \n",MULT) ; printf("I run %ld problems \n",total_problems) ; if (deadlines) printf("Problems have deadlines \n") ; if (!deadlines) printf("Problems don't have deadlines \n") ; printf("My test strategy is %ld \n",test_strategy) ; } */ flag = aloci(&stored_machine,MAXOPER) * aloci(&labelled_list,MAXOPER) * aloci(&which_job,MAXOPER) * aloci(&actrelease,MAXOPER) * aloci(&releases,MAXOPER) * aloci(&tails,MAXOPER) * aloci(&moddeadline,MAXOPER) * aloci(&actdeadline,MAXOPER) * aloci(&processing_time,MAXOPER) * aloci(&operations,MAXJOBIS) * aloci(&pdc,MAXOPER) * aloci(&scs,MAXOPER) * aloci(&LIST,MAXOPER) * aloci(&POS,MAXOPER) * aloci(&which_machine,MAXOPER) * aloci(&jobpred,MAXOPER) * aloci(&jobsucc,MAXOPER) * aloci(&macpred,MAXOPER) * aloci(&macsucc,MAXOPER) * aloci(&position,MAXOPER) * aloci(&best_solution,MAXOPER) * aloci(&best_tails,MAXOPER) * aloci(&BEST_SCHEDULE,MAXOPER) * aloci(&BEST_SCHEDULE_global,MAXOPER) * aloci(&best_intro,MAXMACHINES) ; if (!flag) { printf("Memory problems .... \n") ; exit(1) ; } flag = aloci(&machine_total,MAXMACHINES) * aloci(&machine_sched,MAXMACHINES) * aloci(&introd,MAXMACHINES) * aloci(&bottleneck_order,MAXMACHINES) ; if (!flag) { printf("Memory problems .... \n") ; exit(1) ; } /* * arrays for the one machine problems */ flag = aloci(&pset,MAXJOBS) * aloci(&affect,MAXJOBS) * aloci(&release,MAXJOBS) * aloci(&deadl,MAXJOBS) * aloci(&tail,MAXJOBS) * aloci(&pt,MAXJOBS) * aloci(&tpredo,MAXJOBS) ; if (!flag) { printf("Memory problems .... \n") ; exit(1) ; } flag = aloci(&tsucco,MAXJOBS) * aloci(&zero,MAXJOBS) * aloci(&st,MAXJOBS) * aloci(&schedule,MAXJOBS) * aloci(&thesis,MAXJOBS) * aloci(&set,MAXJOBS) * aloci(&previous,MAXJOBS) * aloci(&order,MAXJOBS) * aloci(&init_order,MAXJOBS) * aloci(&iorder,MAXJOBS) * aloci(&moda,MAXJOBS) * aloci(&modby,MAXJOBS) * aloci(&parcs,MAXJOBS) * aloci(&tordering,MAXJOBS) * aloci(&dpt,MAXJOBS) * aloci(&temp_rls,MAXJOBS) * aloci(&temp_tls,MAXJOBS) * aloci(&temp_affect,MAXJOBS) * aloci(&temp_tpredo,MAXJOBS) * aloci(&temp_tsucco,MAXJOBS) * aloci(&old_tpredo,MAXJOBS) * aloci(&old_tsucco,MAXJOBS) * aloci(&keep_rls,MAXJOBS) * aloci(&keep_tls,MAXJOBS) * aloci(&keep_pt,MAXJOBS) * aloci(&compl,MAXJOBS) * aloci(&besti,MAXJOBS) ; if (!flag) { printf("Memory problems .... \n") ; exit(1) ; } flag = alocp((void ***) &predo,MAXJOBS) * alocp((void ***) &succo,MAXJOBS) * alocp((void ***) &delay,MAXJOBS) * alocp((void ***) &inverse_delay,MAXJOBS) * alocp((void ***) &temp_delay,MAXJOBS) * alocp((void ***) &temp_predo,MAXJOBS) * alocp((void ***) &temp_succo,MAXJOBS) * alocp((void ***) &old_predo,MAXJOBS) * alocp((void ***) &old_succo,MAXJOBS) * alocp((void ***) &old_delay,MAXJOBS) * alocp((void ***) &job_operations,MAXJOBIS) * alocp((void ***) &machine_operations,MAXMACHINES) ; if (!flag) { printf("Memory problems .... \n") ; exit(1) ; } for (i=0;i= 0)) { if (test_strategy != 29) { Upper_Bound = ((long) RAND_MAXI) ; UB_global = ((long) RAND_MAXI ); lateness = ((long) RAND_MAXI) ; lateness_global = ((long) RAND_MAXI ); my_seq_machines = 0 ; guess_modified = 0 ; printf("%f dseed\n",dseed) ; if ( j == 0 ) { dseed = 1 ; } //((double) (atoi(argv[2]))) ; //qqq else { dseed = 1 + ((j-1) * 567) ; } if (j==0 ) { LONGRUN = 0;} else { LONGRUN = 1 ; } total_reopt = 0 ; SB_GLS1(which_job, j, 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) ; } solut [ j ] = Upper_Bound ; // STOPTIME(1) ; // printf("Execution time was %f seconds ", // (((double) USERTIME(1)) / 1000.0)) ; // printf("Guess modified %ld times \n",guess_modified) ; } if (((test_strategy >= 2) && (test_strategy <= 3)) || (test_strategy == 29)) { dseed = start2 ; /* printf("My strategy is %ld\n",test_strategy) ; SB_GLS2(j, 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, my_seq_machines, introd, bottleneck_order, &lateness) ; solut [ j ] = Upper_Bound ; */ } if (MYLONGRUN == 1) { test_strategy = 3 ; } if (test_strategy == 3) { dseed = start3 ; printf("Run RGLSk ... \n") ; SB_RGLSk(j, which_job, SB_RGLSk_bound, SB_RGLSk_cpu, number_of_runs, &LB, &my_seq_machines, m, my_jobs, finishing, macsucc, macpred, jobsucc, jobpred, which_machine, oper, 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) ; solut [ j ] = Upper_Bound ; } if (test_strategy == 10) { LB = 0 ; ACTIVE_SCHEDULE(run_it, m, my_jobs, oper, macpred, macsucc, jobpred, jobsucc, finishing, 0, which_job, machine_sched, releases, tails, operations, processing_time, which_machine, actdeadline, moddeadline, actrelease, pdc, scs, LIST, POS, machine_total, position) ; } if ((test_strategy == 9) || (test_strategy == -9)) { LB = 0 ; if (test_strategy == -9) MAX_ITER_WITHOUT_IMPR = 120 ; ACTIVE_SCHEDULE(run_it, m, my_jobs, oper, macpred, macsucc, jobpred, jobsucc, finishing, 0, which_job, machine_sched, releases, tails, operations, processing_time, which_machine, actdeadline, moddeadline, actrelease, pdc, scs, LIST, POS, machine_total, position) ; sequenced_machines = m ; /* STARTTIME(5) ; */ GLS(m, my_jobs, finishing, oper, macpred, macsucc, jobpred, jobsucc, max_iter, 0, sequenced_machines, depthnew, maxdepth, &LB, machine_sched, actrelease, releases, tails, moddeadline, actdeadline, processing_time, operations, pdc, scs, LIST, POS, machine_total, position, which_machine, 0, 0) ; Upper_Bound = releases [ finishing ] ; /* STOPTIME(5) ; printf("Cpu time: %f \n",((double) USERTIME(5)) / 1000.0) ; cpu_gls [ j ] = cpu_gls [ j ] + (((double) USERTIME(5)) / 1000.0) ; */ /* * modify the best upper bound from all the runs */ if (Upper_Bound < best_upper_bound) best_upper_bound = Upper_Bound ; printf("Best bound from the run = %ld, Best upper bound %ld \n", Upper_Bound,best_upper_bound) ; best_gap_gls [ j ] = best_gap_gls [ j ] + (((((double) best_upper_bound ) - ((double) best_lb))/ ((double) best_lb))*100.0) ; printf("*********************************** \n") ; /* * delete the machines first and recalculate releases, tails * before applying fixing */ for (i=1;i<=m;i++) DELETE_MACHINE(i, 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); #ifdef FIXING_WANTED simple_fixing_of_the_arcs(releases, tails, processing_time, machine_total, m, Upper_Bound) ; #endif fflush(stdout) ; for (jj = 0 ; jj < 10 ; jj++) { total_cpu [ jj ] = total_cpu [ jj ] + cpu_times [ jj ] ; if (my_bounds [ jj ] < Best_Sol [ jj ] ) Best_Sol [ jj ] = my_bounds [ jj ] ; if (my_bounds [ jj ] > Worst_Sol [ jj ] ) Worst_Sol [ jj ] = my_bounds [ jj ] ; Average_Sol [ jj ] = Average_Sol [ jj ] + my_bounds [ jj ] ; } } } if (test_strategy == 9 ) { for (jj = 0 ; jj < 10 ; jj++) { Average_Sol [ jj ] = (Average_Sol [ jj ] / ((double) 1)) ; } #ifdef ALL_RESULTS printf("-------------------------------------------------------- \n") ; printf("Best Solution Worst Solution Avergae Solution \n") ; for ( jj = 0; jj < 10 ; jj++) { printf(" %10.0f %10.0f %15.3f %f \n",Best_Sol [ jj ], Worst_Sol [ jj ] ,Average_Sol [ jj ] , cpu_times [ jj ]) ; } #endif #ifdef TEST_PATHS printf("I am printing all results \n") ; for ( jj =1 ; jj<=m ; jj++ ) { printf("Machine %ld , %f \n",jj, ((machine_critical[jj] / total_schedules)*100.0)) ; } printf("Average number of crit. machines %f \n", ((my_critical_machines / total_schedules))) ; #endif for ( jj = 0; jj < 10 ; jj++) { tgap [ jj ] = tgap [ jj ] + (((((double) Average_Sol [ jj ] ) - ((double) best_lb))/ ((double) best_lb))*100.0) ; } #ifdef ALL_RESULTS printf("How many times more critical %f\n",((multiple_critical_machines/ total_schedules)*100.0)) ; #endif if (test_strategy != -8 ) printf("******************************************************** \n") ; } else { for (j=0 ; j < 1 ; j++) { SB_GLS1_gap [ j ] = SB_GLS1_gap [ j ] + ((( SB_GLS1_bound [ j ] - ((double) best_lb))/ ((double) best_lb))*100.0) ; SB_GLS1_tcpu [ j ] = SB_GLS1_tcpu [ j ] + SB_GLS1_cpu [ j ] ; if ((test_strategy >= 2) && (test_strategy <= 3)) { SB_GLS2_gap [ j ] = SB_GLS2_gap [ j ] + ((( SB_GLS2_bound [ j ] - ((double) best_lb))/ ((double) best_lb))*100.0) ; SB_GLS2_tcpu [ j ] = SB_GLS2_tcpu [ j ] + SB_GLS2_cpu [ j ] ; } if (test_strategy == 3) { SB_RGLSk_gap [ j ] = SB_RGLSk_gap [ j ] + ((( SB_RGLSk_bound [ j ] - ((double) best_lb))/ ((double) best_lb))*100.0) ; SB_RGLSk_tcpu [ j ] = SB_RGLSk_tcpu [ j ] + SB_RGLSk_cpu [ j ] ; } } Average_Sola = 0.0 ; Best_Sola = RAND_MAXI ; Worst_Sola = 0 ; for (j = 0 ; j < 1 ; j++) { if (solut [ j ] < Best_Sola) Best_Sola = solut [ j ] ; if (solut [ j ] > Worst_Sola) Worst_Sola = solut [ j ] ; Average_Sola = Average_Sola + solut [ j ] ; } Average_Sola = (Average_Sola / ((double) 1)) ; #ifdef ALL_RESULTS printf("-------------------------------------------------------- \n") ; printf("Best Solution = %12.0f \n",Best_Sola) ; printf("Worst Solution = %12.0f \n",Worst_Sola) ; printf("Average Solution = %12.3f \n",Average_Sola) ; #endif /* tgap = tgap + (((((double) Average_Sola) - ((double) best_lb))/ ((double) best_lb))*100.0) ; */ if (test_strategy != -8) printf("******************************************************** \n") ; } } if ((test_strategy < 9) && (test_strategy >=0)) { for (j=0;j < 1;j++) { if (deadlines) { printf("Feasible problems SBD_GLS1 = %ld \n",feasible_problems [j]) ; } if (test_strategy == 3){ printf("Run %ld , Average Gap SBGLS3 = %f \n", j,(SB_RGLSk_gap [ j ] / ((double) total_problems))) ; printf("Run %ld , Total normalized cpu SBGLS3 = %f \n",j, (2.5 * SB_RGLSk_tcpu [ j ] )+ (2.5 * SB_GLS1_tcpu [ j ] )); } } } if (test_strategy == 9) { printf(" Avg. CPU seconds - Mean Relative Distance \n") ; for ( jj = 0; jj < 10 ; jj++) { printf(" %f ",((total_cpu [ jj ] ) / ((double) (total_problems * 1)))) ; printf(" %f \n",(tgap [ jj ] / ((double) (total_problems)))) ; } printf("----------------------------------------- \n") ; printf("Percentage of failure(when or lbr) : %f \n", ((failures /trials)*100.0)) ; printf("Total CPU time %f \n",total_time) ; } tcp = 0.0 ; if ((test_strategy == 9) || (test_strategy == -9)) { for (j=0;j<1 ; j++) { printf("Run %ld , Average Gap : %f , Total Cpu %f \n", j+1,(best_gap_gls [ j ] / ((double) total_problems)), (tcp + cpu_gls [ j ] )) ; tcp = tcp + cpu_gls [ j ] ; } } fclose(output_file) ; fprintf(stderr,"\n"); }