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
|
% class definition
%----------------------------------------------------------------------------------------------------------------------
% Fichier: implementation et interface de la classe Fichier
% ---------------------------------------------------------------------------------------------------------------------
classdef Fichier
% définition des propriétés
% ------------------------------------------------------------------------------------------------------------------
properties (GetAccess = public)
nbr_origine = 0; % nombre d'origine dans le réseau
nbr_destination = 0; % nombre de destination dans le réseau
nbr_troncon_total = 0; % nombre total de tronçons dans le réseau
nom = {};
position_troncon = 0;
position_destination = 0;
ListeOrigine = {Origine};
ListeTroncon = {Troncon};
ListeDestination = {Destination};
ListeJonction = {Jonction};
%obj = maClasse();
end
% les méthodes publiques de la classe
% ------------------------------------------------------------------------------------------------------------------
methods
% Constructeurs
% ----------------------------------------------------------------------------------------------------------------
function Fichier = node(nbr_origine, nbr_destination, nbr_troncon_total, ListeOrigine, ListeTroncon, ListeDestination, ListeJonction)
Fichier.nbr_origine = nbr_origine;
Fichier.nbr_destination = nbr_destination;
Fichier.nbr_troncon_total = nbr_troncon_total;
Fichier.ListeOrigine = ListeOrigine;
Fichier.ListeTroncon = ListeTroncon;
Fichier.ListeDestination = ListeDestination;
Fichier.ListeJonction = ListeJonction;
end
% les méthodes d'accès aux propriétés
% ----------------------------------------------------------------------------------------------------------------
function LireFichierConfiguration (obj)
monfichier = 'C:/FichierConfiguration.txt';
config = Fichier ();
nbr_orig = 0;
nbr_tronc = 0;
nbr_dest = 0;
nbr_jonc = 0;
nbr_tronc_total=0;
reseau = fopen(monfichier,'r','n','UTF-8');% open the file
%Test for end-of-file (reseau)Line-by-Line:returns a value of 1 when the file pointer is at the end of the file.Otherwise,it returns 0.
while feof(reseau) == 0
%Traitement de la partie "origine" du fichier
% ------------------------------------------------------------------------------------------------------------------------------------------------------
%Récupération de la valeur de "nombre_origine"
ligne = fgetl(reseau);
disp(ligne); %affichage à lécran
mots = regexp(ligne, '\s+', 'split'); %Renvoie les mots de la ligne separement dans un cell array
nbr_origines = str2num(char(mots(2)));
disp(['nombre d''origine = ', num2str(nbr_origines)]);
%On passe les 3 lignes vides d'entête
fgetl(reseau);
fgetl(reseau);
fgetl(reseau);
%On récupère les données pour chaque ligne de "origine"
for i = 1:nbr_origines
ligne = fgetl(reseau);
mots = regexp(ligne, '\s+', 'split');
%ici on peut récupérer la valeur de chaque mot Pour la mettre dans nos variables, avec char(mots(1)), char(mots(2)), etc.
nom_orig = char(mots(1));
Nom_jonction_destination_orig = char(mots(2));
longueur_orig = str2num(char(mots(3)));
nbr_voies_orig = str2num(char(mots(4)));
vitesse_orig = str2num(char(mots(5)));
debit_orig = str2num(char(mots(6)));
disp(['nom_orig = ', num2str(nom_orig)]);
disp(['Nom_jonction_destination_orig = ', num2str(Nom_jonction_destination_orig)]);
disp(['longueur_orig = ', num2str(longueur_orig)]);
disp(['nbr_voies_orig = ', num2str(nbr_voies_orig)]);
disp(['vitesse_orig = ', num2str(vitesse_orig)])
disp(['debit_orig = ', num2str(debit_orig)]);
orig = Origine();
orig.SetNomOrig(nom_orig);
orig.index_orig = i;
orig.SetNomJonctionDestination(Nom_jonction_destination_orig);
orig.SetLongueurOrig(longueur_orig);
orig.SetNbrVoiesOrig(nbr_voies_orig);
orig.SetVitesseLibreOrig(vitesse_orig);
orig.SetDebitMaxOrig(debit_orig);
config.ListeOrigine{end+1} = orig; %pour rajouter un élément à la liste
tronc = Troncon();
tronc.SetNomTronc(nom_orig);
tronc.index_tronc = i;
%nbr_tronc++
nbr_tronc_total = nbr_tronc_total+1;
tronc.SetLongueurTronc(longueur_orig);
tronc.SetNbrVoiesTronc(nbr_voies_orig);
tronc.SetNomJonctionDestination(Nom_jonction_destination_orig);
tronc.SetNomJonctionOrigine('');
config.ListeTroncon{end+1} = tronc ; %pour rajouter un élément à la liste
end
%On passe une ligne vide
fgetl(reseau);
nbr_orig = nbr_origines;
nbr_origine = nbr_origines;
%Traitement de la partie "troncons" du fichier
% ------------------------------------------------------------------------------------------------------------------------------------------------------
%Récupération de la valeur de "nombre_troncon"
ligne = fgetl(reseau);
disp(ligne); %affichage à lécran
mots = regexp(ligne, '\s+', 'split'); %Renvoie les mots de la ligne separement dans un cell array
nbr_troncons = str2num(char(mots(2)));
disp(['nombre de tronçon = ', num2str(nbr_troncons)]);
%On passe les 3 lignes vides d'entête
fgetl(reseau);
fgetl(reseau);
fgetl(reseau);
%On récupère les données pour chaque ligne de "troncon"
for i = 1:nbr_troncons
ligne = fgetl(reseau);
mots = regexp(ligne, '\s+', 'split');
%ici on peut récupérer la valeur de chaque mot Pour la mettre dans nos variables, avec char(mots(1)), char(mots(2)), etc.
nom_troncon = char(mots(1));
nbr_voies_troncon = str2num(char(mots(2)));
longueur_troncon = str2num(char(mots(3)));
vitesse_troncon = str2num(char(mots(4)));
Nom_jonction_origine_tronc = char(mots(5));
Nom_jonction_destination_tronc = char(mots(6));
disp(['nom_troncon = ', num2str(nom_troncon)]);
disp(['nbr_voies_troncon = ', num2str(nbr_voies_troncon)]);
disp(['longueur_troncon = ', num2str(longueur_troncon)]);
disp(['vitesse_troncon = ', num2str(vitesse_troncon)]);
disp(['Nom_jonction_origine_tronc = ', num2str(Nom_jonction_origine_tronc)]);
disp(['Nom_jonction_destination_tronc = ', num2str(Nom_jonction_destination_tronc)] );
tronc = Troncon();
tronc.SetNomTronc(nom_troncon);
tronc.index_tronc = nbr_tronc_total;
nbr_tronc_total = nbr_tronc_total+1;
tronc.SetNbrVoiesTronc(nbr_voies_troncon);
tronc.SetLongueurTronc(longueur_troncon);
tronc.SetVitesseLibreTronc(vitesse_troncon);
tronc.SetNomJonctionOrigine(Nom_jonction_origine_tronc);
tronc.SetNomJonctionDestination(Nom_jonction_destination_tronc);
config.ListeTroncon{end+1} = tronc; %pour rajouter un élément à la liste
end
%On passe une ligne vide
fgetl(reseau);
%Traitement de la partie "destinations" du fichier
% ------------------------------------------------------------------------------------------------------------------------------------------------------
%Récupération de la valeur de "nombre_destination"
ligne = fgetl(reseau);
disp(ligne); %affichage à lécran
mots = regexp(ligne, '\s+', 'split'); %Renvoie les mots de la ligne separement dans un cell array
nbr_destinations = str2num(char(mots(2)));
disp(['nombre de destination = ', num2str(nbr_destinations)]);
%On passe les 3 lignes vides d'entête
fgetl(reseau);
fgetl(reseau);
fgetl(reseau);
%On récupère les données pour chaque ligne de "destination"
for i = 1:nbr_destinations
ligne = fgetl(reseau);
mots = regexp(ligne, '\s+', 'split');
%ici on peut récupérer la valeur de chaque mot Pour la mettre dans nos variables, avec char(mots(1)), char(mots(2)), etc.
nom_destination = char(mots(1));
Nom_jonction_origine_dest = char(mots(2));
nbr_voies_destination = str2num(char(mots(3)));
longueur_destination = str2num(char(mots(4)));
vitesse_destination = str2num(char(mots(5)));
disp(['nom_destination = ', num2str(nom_destination)]);
disp(['Nom_jonction_origine_dest = ', num2str(Nom_jonction_origine_dest)]);
disp(['nbr_voies_destination = ', num2str(nbr_voies_destination)]);
disp(['longueur_destination = ', num2str(longueur_destination)]);
disp(['vitesse_destination = ', num2str(vitesse_destination)]);
dest = Destination();
dest.SetNomDest(nom_destination);
dest.index_dest=i;
dest.SetNomJonctionOrigine(Nom_jonction_origine_dest);
dest.SetNbrVoiesDest(nbr_voies_destination);
dest.SetLongueurDest(longueur_destination);
dest.SetVitesseLibreDest(vitesse_destination);
config.ListeDestination{end+1} = dest; %pour rajouter un élément à la liste
tronc = Troncon();
tronc.SetNomTronc(nom_destination);
tronc.index_tronc=nbr_tronc_total;
nbr_tronc_total = nbr_tronc_total+1;
tronc.SetLongueurTronc(longueur_destination);
tronc.SetNbrVoiesTronc(nbr_voies_destination);
config.ListeTroncon{end+1} = tronc; %pour rajouter un élément à la liste
end
%On passe une ligne vide
fgetl(reseau);
nbr_tronc_total = nbr_tronc_total;
nbr_dest = nbr_destinations;
%Traitement de la partie "jonctions" du fichier
% ------------------------------------------------------------------------------------------------------------------------------------------------------
%Récupération de la valeur de "nombre_jonction"
ligne = fgetl(reseau);
disp(ligne); %affichage à lécran
mots = regexp(ligne, '\s+', 'split'); %Renvoie les mots de la ligne separement dans un cell array
nbr_jonctions = str2num(char(mots(2)));
disp(['nombre de jonction = ', num2str(nbr_jonctions)]);
%On passe les 3 lignes vides d'entête
fgetl(reseau);
fgetl(reseau);
fgetl(reseau);
%On récupère les données pour chaque ligne de "jonction"
for i = 1:nbr_jonctions
ligne = fgetl(reseau);
mots = regexp(ligne, '\s+', 'split');
%ici on peut récupérer la valeur de chaque mot Pour la mettre dans nos variables, avec char(mots(1)), char(mots(2)), etc.
nom_jonction = char(mots(1));
type_in_jonction = str2num(char(mots(2)));
nbr_in_jonction = str2num(char(mots(3)));
nom_type_entrant = char(mots(4));
type_out_jonction = str2num(char(mots(5)));
nbr_out_jonction = str2num(char(mots(6)));
nom_type_sortant = char(mots(6));
disp(['nom_jonction = ', num2str(nom_jonction)]);
disp(['type_in_jonction = ', num2str(type_in_jonction)]);
disp(['nbr_in_jonction = ', num2str(nbr_in_jonction)]);
disp(['nom_type_entrant = ', num2str(nom_type_entrant)]);
disp(['type_out_jonction = ', num2str(type_out_jonction)]);
disp(['nbr_out_jonction = ', num2str(nbr_out_jonction)]);
disp(['nom_type_sortant = ', num2str(nom_type_sortant)]);
jonc = Jonction();
jonc.SetNomJonc(nom_jonction);
for m=0:nbr_in_jonction
jonc.Setlist_in(nom_type_entrant);
disp(['nom_type_entrant:', num2str(nom_type_entrant)]);
end %for(m)
for y=0:nbr_out_jonction
jonc.Setlist_out(nom_type_sortant);
disp(['nom_type_sortant:', num2str(nom_type_sortant)]);
end %for(y)
config.ListeJonction{end+1} = jonc; %pour rajouter un élément à la liste
disp(['nom_jonction:', num2str(nom_jonction)]);
disp(['type_in_jonction:', num2str(type_in_jonction)]);
disp(['nbr_in_jonction:', num2str(nbr_in_jonction)]);
disp(['type_out_jonction:', num2str(type_out_jonction)]);
disp(['nbr_out_jonction:', num2str(nbr_out_jonction)]);
end
return;
end
fclose(reseau);
end %fonction LireFichierConfiguration
% ------------------------------------------------------------------------------------------------------------------------------------------------------
function [result]= GetJonction (nom)
result.Jonction = NULL;
taille = numel(config.ListeJonction); %pour dénombrer les éléments de ma liste : obtenir le Nombre d'éléments
for i=0:taille
%accéder à un élément de position "i" de ma liste
jonc.Jonction = config.ListeJonction {i}; %L'indexage s'effectue:soit avec()pour récupérer la cellule ;soit avec{}pour récupérer la valeur contenue dans la cellule
nom_jonction = jonc.GetNomJonc();
if strcmp (nom_jonction, nom) %comparaison entre 2 string: nom_jonction et nom
result = jonc;
return;
end
end
return ; %result;
end
% ------------------------------------------------------------------------------------------------------------------------------------------------------
function GetTroncon (nom, position_troncon)
taille = numel(config.ListeTroncon);
for i=0:taille
%accéder à un élément de position "i" de ma liste
tronc.Troncon = config.ListeTroncon{i};
nom_troncon = tronc.GetNomTronc();
if strcmp (nom_troncon, nom) %comparaison entre 2 string: nom_troncon et nom
position_troncon = i;
return; % tronc;
end
end
return; % NULL;
end
% ------------------------------------------------------------------------------------------------------------------------------------------------------
function [position_destination]= GetDestination (nom)
taille = numel(config.ListeDestination);
for i=0:taille
%accéder à un élément de position "i" de ma liste
dest.Destination = config.ListeDestination{i}; %à vérifier
nom_destination = dest.GetNomDest();
if strcmp (nom_destination, nom) %comparaison entre 2 string: nom_troncon et nom
position_destination = i;
return; % dest;
end
end
return, % NULL;
end
% ------------------------------------------------------------------------------------------------------------------------------------------------------
function [nom_jonction] = ListerJonctions (ListeJonction)
taille = numel(ListeJonction);
for i=0:taille
%accéder à un élément de position "i" de ma liste
jonc.Jonction = ListeJonction(i);
nom_jonction = jonc.GetNomJonc();
end
end
% ------------------------------------------------------------------------------------------------------------------------------------------------------
end % end of public methods
end % end of class definition |
Partager