2
I have a file matriz_caminhos.txt
with 20 rows and 20 columns, I need to access it and take the data as an array.
So far, I just got it to scan the file and return me 20 vectors.
Follows the code: .
<?php
$ponteiro1 = fopen("C:/xampp/htdocs/www/grafoai/inputs/matriz_caminhos.txt","r");
while (!feof($ponteiro1)) {
$linha1 = fgets($ponteiro1, 4096);
//var_dump($linha1);
$caminhos1 = array_map('trim', explode(",", $linha1)); //cidades = vetor
$vetorCaminhos = array();
foreach ($caminhos1 as $key1 => $value1) {
//Array
$vetorCaminhos = str_split($value1);
echo "<br><br>";
print_r($vetorCaminhos);
} //Fim do Foreach
} //Fim do While
fclose($ponteiro1)
?>
The file "matriz_paths.txt" contains the following data:
01010000000000000000
10100000000000000000
01010000000000000000
00100100000000000000
00001010000000000000
00000101000000000000
00000010100000000000
00000001010001000000
00010000100001000000
10100000011000000000
00010000000100000000
00000000110100000000
00000000001011100000
00000000000100000000
00000000000100010100
00000000000000101000
00000000000000010000
00000000000000100000
00000000000000000101
00000000000000000010
I am using the following map as an example. Each number 1 that is in the txt file represents the position of the city on the map and its links (In order to know, eventually, which is the best way to go).
I was trying to take the data as vector and then turn it into matrix. There is some possibility of already take this data as matrix? If so, what? If not, is there any possibility of turn these 20 vectors into a matrix?
Just for example, when I chose as origin the city "Arad" and destination city as "Eforie" and chose the Amplitude method. I must use a chained list to find the best way possible by the amplitude method.
After I select city of origin, destination and method, I with the code above, I was able to print the 20 vectors, as shown in the image down below:
This is a graph problem, not chained list, as it is on the tag
– Sveen
In the teacher’s explanation, from what I understood, I should use a chained list to store the data to do the search.
– Marcielli Oliveira
Yes graphs have two most popular implementations, matrix and adjacency list. Chained list uses pointers to connect instantiated structures. http://www.professeurs.polymtl.ca/michel.gagnon/Disciplinas/Bac/Grafos/RepImpl/rep_impl.html
– Sveen