1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
| #include<stdio.h>
#include<stdlib.h>
#include <math.h>
#include <time.h>
#define MAX 500
/**************************************
Structures de donnes
**************************************/
typedef struct client
{
int identifiant; /* numero du client */
double abscisse; /* abscisse du client i */
double ordonee; /* ordonnee du client i */
int demande; /* demande du client */
int frequence; /* frequence de visite du client */
int Nbvisites; /* nombre de visite du client */
int temps_service; /* temps de service du client i */
int borne_inf_tw; /* début de la fenetre du temps du client i */
int borne_sup_tw; /* fin de la fenetre du temps du client i */
}client;
typedef struct donnee
{
int type; /* type MDIRPTW */
int nbr_vehicules; /* nombre de véhicules */
int nbr_clients; /* nombre de clients */
int nbr_periodes; /* nombre de periodes */
int nbr_depots; /* nombre de depots */
int nbr_usine; /* nombre d'usines */
double **dist; /* distance */
}donnee;
typedef struct usine1
{
int cap_usine; /* capacite de l'usine */
int cout_poss; /* cout de possession de l'usine */
int cout_rup_stock; /* cout de rupture de stock de l'usine */
int cout_stock_sec; /* cout de stock de securite de l'usine */
int *dem_jour; /* demande journalière de l'usine pour chaque période */
}usine1;
typedef struct vehicule
{
int auton_max; /* autonomie du stransport */
int capa_vehicule; /* capacite du vehicule */
int nbr_vehicules; /* nombre de vehicules */
}vehicule;
typedef struct depot
{
int identifiant; /* numero du client */
double abscisse; /* abscisse du client i */
double ordonee; /* ordonnee du client i */
int demande; /* demande du client */
int frequence; /* frequence de visite du client */
int temps_service; /* temps de service du client i */
int borne_inf_tw; /* début de la fenetre du temps du client i */
int borne_sup_tw; /* fin de la fenetre du temps du client i */
int cout_uni_liv; /* cout unitaire de livraison */
int cout_uni_st; /* cout unitaire de stockage */
int capa_depot; /* capacite du depot */
int liste_c; /* liste des clients */
}depot;
typedef struct tournee
{
int pred; /*le predecesseur du client i */
int succ; /*le successeur du client i */
}tournee;
typedef struct JOURS
{
int *nbr_clients; /* number of clients */
int *listcust; /* liste of clients */
int *cust; /* clients par jour */
int TotDemCust; /* demande totale des clients par jour */
//CHAINES *Customers; /* number of clients */
//CHAINES *ListeCltPossible; /* liste des clients possible par jour */
//VECTI *D; /* charge des dépôts */
//VECTI *T; /* charge des tournees */
}JOURS;
/**************************************
programme principal
**************************************/
void Initialisation (donnee *data, client *cust, depot *dep,usine1 *usine, vehicule *camion, JOURS *days)
{
int i;
for (i=1; i<=data->nbr_clients; i++)
{
cust[i].Nbvisites=0;
}
}
// recherche des clients les plus eloignes % depots //
void rechercher_max_distance(donnee *data)
{
int j = 1;
int i;
double max;
int depot, num_client;
for (i=1; i<=data->nbr_depots; i++) {
max = data->dist[i][0];
for (j = data->nbr_depots; j <= data->nbr_clients + data->nbr_depots; j++)
{
if (data->dist[i][j] > max){
max = data->dist[i][j];
depot = i;
num_client = j - data->nbr_depots;
}
}
if((j - data->nbr_depots - 1) == data->nbr_clients)
printf("Le client %d est eloignee du depot %d, sa distance est de %f\n", num_client, depot, max);
}
}
//Affectation des clients aux jours
void affect_client_to_days(JOURS *days, donnee *data, usine1 *usine, client *cust){
int j;
int t;
int jr;
int dem;
int it=0;
int nbr_c;
int nbr_t;
srand(time(NULL));
int nombre_aleatoire = 0;
for (jr=1; jr<=data->nbr_periodes; jr++)
{
days[jr].TotDemCust = 0;
days[jr].nbr_clients= 0;
while ((usine->dem_jour[jr] > days[jr].TotDemCust) || (it<1000));
{
int nombre_aleatoire = rand()%data->nbr_clients+1;
printf("affecter le client numero %d a la periode %d",nombre_aleatoire, nbr_t);
if((cust[j].Nbvisites < cust[j].frequence)&& (days[jr].cust[j]=0))
{
days[jr].nbr_clients++;
cust[j].Nbvisites=j++;
days[jr].cust[j]=1;
days[jr].listcust[days[jr].nbr_clients]=j;
days[jr].TotDemCust=cust[j].demande;
}
it++;
}
}
}
void ChargeDonnees(donnee *data,client *cust, depot *dep,usine1 *usine, vehicule *camion)
{
int id;
int nd;
int k;
int l;
int m;
int cu_liv;
int cu_st;
int cap_d;
int n;
double abs;
double ord;
int dde;
int frq;
int tps_service;
int b_inf_tw;
int b_sup_tw;
int i;
int j;
int nbr_v, nbr_c, nbr_d, nbr_u, nbr_t;
int cu,cp,crs,css;
FILE *fp;
fp = fopen("donne.txt", "r");
if(fp == NULL)
{
printf("Impossible d'ouvrir fichier donnee.txt \n");
exit (-1);
}
fscanf(fp,"%d %d %d %d %d %d \n",&data->type,&data->nbr_vehicules,&data->nbr_clients,&data->nbr_periodes,&data->nbr_depots,&data->nbr_usine);
printf("%d %d %d %d %d %d\n",data->type,data->nbr_vehicules,data->nbr_clients,data->nbr_periodes,data->nbr_depots,data->nbr_usine);
fscanf(fp,"%d %d %d %d \n",&usine->cap_usine,&usine->cout_poss,&usine->cout_rup_stock,&usine->cout_stock_sec);
printf("%d %d %d %d\n",usine->cap_usine,usine->cout_poss,usine->cout_rup_stock,usine->cout_stock_sec);
for(l=1;l<=data->nbr_periodes;l++)
{
fscanf(fp,"%d \n",&usine->dem_jour[l]);
printf("%d \n",usine->dem_jour[l]);
}
for(m=1;m<=(data->nbr_periodes*data->nbr_depots);m++)
{
fscanf(fp,"%d %d\n",&camion[m].auton_max,&camion[m].capa_vehicule);
printf("%d %d\n",camion[m].auton_max,camion[m].capa_vehicule);
}
for(n=1;n<=data->nbr_depots;n++)
{
fscanf(fp,"%d %lf %lf %d %d %d %d %d %d %d %d \n",&dep[n].identifiant,&dep[n].abscisse,&dep[n].ordonee,&dep[n].temps_service,&dep[n].demande,&dep[n].frequence,&dep[n].borne_inf_tw,&dep[n].borne_sup_tw,&dep[n].cout_uni_liv,&dep[n].cout_uni_st,&dep[n].capa_depot);
printf("%d %lf %lf %d %d %d %d %d %d %d %d\n",dep[n].identifiant,dep[n].abscisse,dep[n].ordonee,dep[n].temps_service,dep[n].demande,dep[n].frequence,dep[n].borne_inf_tw,dep[n].borne_sup_tw,dep[n].cout_uni_liv,dep[n].cout_uni_st,dep[n].capa_depot);
}
for(i=1;i<=data->nbr_clients;i++)
{
fscanf(fp,"%d %lf %lf %d %d %d %d %d\n",&cust[i].identifiant,&cust[i].abscisse,&cust[i].ordonee,&cust[i].temps_service,&cust[i].demande,&cust[i].frequence,&cust[i].borne_inf_tw,&cust[i].borne_sup_tw);
printf("%d %lf %lf %d %d %d %d %d\n",cust[i].identifiant,cust[i].abscisse,cust[i].ordonee,cust[i].temps_service,cust[i].demande,cust[i].frequence,cust[i].borne_inf_tw,cust[i].borne_sup_tw);
}
/**************************************
Calcul de la matrice de distance
**************************************/
/*matrice de distance entre les clients et les depots*/
for (i=1; i<=data->nbr_depots; i++)
for (j = 1; j <= data->nbr_clients; j++)
{
data->dist[i][data->nbr_depots+j]=(double)(pow((dep[i].abscisse - cust[j].abscisse)
*(dep[i].abscisse - cust[j].abscisse)
+(dep[i].ordonee - cust[j].ordonee )
*(dep[i].ordonee - cust[j].ordonee ),0.5));
data->dist[data->nbr_depots+j][i]=data->dist[i][data->nbr_depots+j];
}
/*matrice de distance entre les clients*/
for (i=1; i<=data->nbr_clients; i++)
for (j = i; j <= data->nbr_clients; j++)
{
data->dist[data->nbr_depots+i][data->nbr_depots+j]=(double)(pow((cust[i].abscisse - cust[j].abscisse)
*(cust[i].abscisse - cust[j].abscisse)
+(cust[i].ordonee - cust[j].ordonee )
*(cust[i].ordonee - cust[j].ordonee ),0.5));
data->dist[data->nbr_depots+j][data->nbr_depots+i]=data->dist[data->nbr_depots+i][data->nbr_depots+j];
}
fclose (fp);
}
int main (void)
{
int i;
int j;
int jr;
int nbr_v, nbr_c, nbr_d, nbr_u, nbr_t;
int nombre_aleatoire;
srand ( time(NULL) );
FILE *fp;
client *cust=NULL;
usine1 *usine=NULL;
vehicule *camion=NULL;
depot *dep=NULL;
donnee *data=NULL;
JOURS *days=NULL;
tournee *tour=NULL;
fp = fopen("donne.txt","r");
if (fp == NULL)
{ printf("\n Erreur a l'ouverture du fichier.\n\a");
exit(0); };
fscanf(fp,"%d\n",&i);
fscanf(fp,"%d\n",&nbr_v);
fscanf(fp,"%d\n",&nbr_c);
fscanf(fp,"%d\n",&nbr_d);
fscanf(fp,"%d\n",&nbr_t);
fscanf(fp,"%d\n",&nbr_u);
fclose(fp);
cust = (client *) calloc ((unsigned)nbr_c+1, (unsigned)(sizeof(client )) );
if ( cust == NULL )
{
printf("Not enough space for cust\n");
exit(1);
}
usine = (usine1 *) calloc ((unsigned)nbr_u+1, (unsigned)(sizeof(usine )) );
if ( usine == NULL )
{
printf("Not enough space for usine\n");
exit(1);
}
camion = (vehicule *) calloc ((unsigned)nbr_v+1, (unsigned)(sizeof(vehicule )) );
if ( camion == NULL )
{
printf("Not enough space for usine\n");
exit(1);
}
dep = (depot *) calloc ((unsigned)nbr_d+1, (unsigned)(sizeof(depot )) );
if ( dep == NULL )
{
printf("Not enough space for usine\n");
exit(1);
}
data = (donnee *) calloc ((unsigned)1, (unsigned)(sizeof(donnee )) );
if ( data == NULL )
{
printf("Not enough space for data\n");
exit(1);
}
data->dist = (double **) calloc((((nbr_d+nbr_c)+2)),sizeof(double *));
if (data->dist == NULL)
{ printf("Memoire insuffisante pour data->dist!");
exit(0); }
for(j=0; j<=nbr_d+nbr_c+1; j++)
{
data->dist[j] = (double *) calloc((((nbr_d+nbr_c)+2)),sizeof(double));
if (data->dist[j] == NULL)
{ printf("Memoire insuffisante pour data->dist[j]!");
exit(0); }
}
ChargeDonnees(data,cust,dep,usine,camion);
days = (JOURS *) calloc ((unsigned)data->nbr_periodes+1, (unsigned)(sizeof(JOURS )) );
if ( days == NULL )
{
printf("Not enough space for days\n");
exit(1);
}
for (j=0; j<=data->nbr_periodes; j++)
{
days[jr].cust = (int *) calloc(((data->nbr_clients+1)),sizeof(int));
if (days[jr].cust == NULL)
{ printf("Memoire insuffisante pour days[j].cust!");
exit(0);
}
days[jr].listcust = (int *) calloc(((data->nbr_clients+1)),sizeof(int));
if (days[jr].listcust == NULL)
{ printf("Memoire insuffisante pour days[j].listcust!");
exit(0);
}
days[jr].nbr_clients = (int *) calloc(((data->nbr_clients+1)),sizeof(int));
if (days[jr].nbr_clients == NULL)
{ printf("Memoire insuffisante pour days[jr].nbr_clients!");
exit(0);
}
Initialisation(data,cust,dep,usine,camion,days);
printf("\n calcul de la distance entre les depots et les clients\n ");
for (i=1; i<=data->nbr_depots; i++)
for (j = 1; j <= data->nbr_clients; j++)
{
printf("\n la distance entre le depot %d et le client %d = %lf",i,j,data->dist[i][data->nbr_depots+j]);
}
printf("\n recherche des clients les plus eloignes par apport aux depots\n ");
rechercher_max_distance(data);
affect_client_to_days(days,data,usine,cust);
//printf("\n calcul de la distance entre les clients\n ");
/*for (i=1; i<=data->nbr_clients; i++)
for (j = i; j <= data->nbr_clients; j++)
{
printf("\n la distance entre le client %d et le client %d = %lf",i,j,data->dist[data->nbr_depots+i][data->nbr_depots+j]);
}*/
getchar();
return EXIT_SUCCESS;
}
} |