Makefile: dodano symbole do kompilacji
main.cpp: Działa troszkę bardziej
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
build:
|
build:
|
||||||
g++ -Iinclude main.cpp
|
g++ -g -Iinclude main.cpp
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f a.out
|
rm -f a.out
|
||||||
|
|||||||
@@ -31,12 +31,14 @@ uruchomienie programu bez parametrów powoduje wypisanie krótkiej instrukcji
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/cxxopts.hpp"
|
#include "include/cxxopts.hpp"
|
||||||
|
#include "include/types.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
double nieskończoność=std::numeric_limits<double>::max();
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -48,23 +50,25 @@ cxxopts::Options options("Kurier", "Program rozwiązujący problem kuriera");
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
typedef std::map<std::string, std::map<std::string, double>> mapa;
|
||||||
std::vector<std::vector<double>> macierzOdległości;
|
mapa mapaOdległości;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief Funkcja czyszcząca stringi z niepotrzebnych znaków
|
* @brief Funkcja czyszcząca stringi z niepotrzebnych znaków
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
void czyscStringa( string &str, char* znakiDoCzyszczenia ) {
|
void czyscStringa( string &str, char* znakiDoCzyszczenia ) {
|
||||||
for ( unsigned int i = 0; i < strlen(znakiDoCzyszczenia); ++i ) {
|
for ( unsigned int i = 0; i < strlen(znakiDoCzyszczenia); ++i ) {
|
||||||
str.erase( remove(str.begin(), str.end(), znakiDoCzyszczenia[i]), str.end() );
|
str.erase( remove(str.begin(), str.end(), znakiDoCzyszczenia[i]), str.end() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dijkstruj(mapa doDijkstrnięcia){
|
||||||
|
for(auto miasto : doDijkstrnięcia)
|
||||||
|
{
|
||||||
|
// doDijkstrnięcia.rbegin()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Funkcja parsująca dane wejściowe.
|
* @brief Funkcja parsująca dane wejściowe.
|
||||||
*
|
*
|
||||||
@@ -76,10 +80,22 @@ void czyscStringa( string &str, char* znakiDoCzyszczenia ) {
|
|||||||
*/
|
*/
|
||||||
void parseInput(string inputFile) {
|
void parseInput(string inputFile) {
|
||||||
ifstream file(inputFile);
|
ifstream file(inputFile);
|
||||||
std::string token;
|
std::string token,miastoA,miastoB,dystans,rodzajRelacji;
|
||||||
while(std::getline(file, token, ',')) {
|
while(std::getline(file, token, ',')) {
|
||||||
czyscStringa(token, "()");
|
czyscStringa(token, "(:)");
|
||||||
std::cout << token << std::endl;
|
istringstream tokenstream(token);
|
||||||
|
tokenstream >> miastoA >> rodzajRelacji >> miastoB >> dystans;
|
||||||
|
if (rodzajRelacji.compare("-")==0) {
|
||||||
|
// Jeśli drugie miasto zaczyna się od znaku '-', to znaczy, że jest to droga dwukierunkowa.
|
||||||
|
// Dodajemy odległość do mapy dla obu kierunków.
|
||||||
|
mapaOdległości[miastoA][miastoB] = stod(dystans);
|
||||||
|
mapaOdległości[miastoB][miastoA] = stod(dystans);
|
||||||
|
} else if (rodzajRelacji.compare("->")==0) {
|
||||||
|
// Jeśli drugie miasto zaczyna się od znaku '>', to znaczy, że jest to droga jednokierunkowa.
|
||||||
|
// Dodajemy odległość tylko w jednym kierunku.
|
||||||
|
mapaOdległości[miastoA][miastoB] = stod(dystans);
|
||||||
|
mapaOdległości[miastoB][miastoA] = nieskończoność;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -109,9 +125,10 @@ int main (int argc, char *argv[])
|
|||||||
if (result.count("input") && result.count("output")) {
|
if (result.count("input") && result.count("output")) {
|
||||||
plikWejsciowy = result["input"].as<string>();
|
plikWejsciowy = result["input"].as<string>();
|
||||||
parseInput(plikWejsciowy);
|
parseInput(plikWejsciowy);
|
||||||
|
dijkstruj(mapaOdległości);
|
||||||
plikWyjsciowy = result["output"].as<string>();
|
plikWyjsciowy = result["output"].as<string>();
|
||||||
} else {
|
} else {
|
||||||
std::cout << std::endl << "Błąd 03 - nie podano wymaganych parametrów" << std::endl << std::endl << std::endl << options.help() << std::endl;
|
std::cout << std::endl << "Błąd - nie podano wymaganych parametrów" << std::endl << std::endl << std::endl << options.help() << std::endl;
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
if (debug == true) {
|
if (debug == true) {
|
||||||
@@ -123,5 +140,6 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user