/*****************************************************************/ /* */ /* Program to create multi-level directed graphs from */ /* directed graphs */ /* */ /* Output of this program is input for the program to solve */ /* the multi-level network optimization problem */ /* */ /* Author: Frederico R. B. da Cruz */ /* Department of Industrial Engineering and */ /* Operations Research */ /* University of Massachusetts at Amherst */ /* USA */ /* */ /* E-mail: fcruz@sml1.ecs.umass.edu */ /* */ /* Version: 2.00 */ /* */ /* Date: Nov./95 */ /* */ /*****************************************************************/ #include #include #include "ty.h" int main(int argc, char *argv[]) { char *line; char Line[LLENGTH]; int l, Index, Level, n_Levels, From, To; float Distance, *UnitaryFixCost, *UnitaryVarCost, *AllocationCost; n_Levels = 1; if ( argc < ( 1 + 2 * n_Levels + n_Levels ) ) { fprintf(ERRFILE, "Usage: cmg f^1_ij c^1_ij ... f^m_ij c^m_ij f^1_i ... f^m_i < input\n"); exit(0); } line = &Line[0]; fgets(line, LLENGTH, INFILE); fputs(line, OUTFILE); fgets(line, LLENGTH, INFILE); fputs(line, OUTFILE); fgets(line, LLENGTH, INFILE); fputs(line, OUTFILE); fgets(line, LLENGTH, INFILE); fputs(line, OUTFILE); sscanf(line, "%d", &n_Levels); if ( argc < ( 1 + 2 * n_Levels + n_Levels ) ) { fprintf(ERRFILE, "Usage: cmg f^1_ij c^1_ij ... f^m_ij c^m_ij f^1_i ... f^m_i < input\n"); exit(0); } UnitaryFixCost = (float *) calloc( n_Levels, sizeof(float) ); UnitaryVarCost = (float *) calloc( n_Levels, sizeof(float) ); AllocationCost = (float *) calloc( n_Levels, sizeof(float) ); for (l = 0; l < n_Levels; l++) { sscanf(argv[1 + 2*l ], "%f", &UnitaryFixCost[l]); sscanf(argv[2 + 2*l ], "%f", &UnitaryVarCost[l]); sscanf(argv[1 + 2*n_Levels + l], "%f", &AllocationCost[l]); } fgets(line, LLENGTH, INFILE); fputs(line, OUTFILE); fgets(line, LLENGTH, INFILE); fprintf(OUTFILE, "Orig Dest"); for ( l = 0; l < n_Levels; l++) fprintf(OUTFILE, " f^%d_ij c^%d_ij", l+1, l+1); fprintf(OUTFILE,"\n"); fgets(line, LLENGTH, INFILE); while ( sscanf(line, "%d %d %f", &From, &To, &Distance) == 3 ) { fprintf(OUTFILE,"%4d %4d", From, To); for ( l = 0; l < n_Levels; l++) fprintf(OUTFILE, " %6.0f %6.0f", Distance*UnitaryFixCost[l], Distance*UnitaryVarCost[l] ); fprintf(OUTFILE, "\n"); fgets(line, LLENGTH, INFILE); } fputs(line, OUTFILE); fgets(line, LLENGTH, INFILE); fprintf(OUTFILE, "Index Level fi\n"); fgets(line, LLENGTH, INFILE); while ( sscanf(line, "%d %d", &Index, &Level) == 2 ) { fprintf(OUTFILE," %4d %4d %6.0f\n", Index, Level, AllocationCost[Level-1]); fgets(line, LLENGTH, INFILE); } fputs(line, OUTFILE); while ( fgets(line, LLENGTH, INFILE) != NULL ) fputs(line, OUTFILE); free(UnitaryFixCost); free(UnitaryVarCost); free(AllocationCost); return(0); }