Seguinte: fbruta.h
Acima: Códigos-fonte: Solução por força
Anterior: inout.h
inout.c
001 #include "inout.h"
002 #include <stdio.h>
003 #include <string.h>
004 #include <limits.h>
005 #include <stdlib.h>
006 #include <ctype.h>
007
008
009
010
011 int readPcvFile(const char *szFName, TPcvData *PcvData)
012 {
013 static const char *szDataDelim = "EDGE_WEIGHT_SECTION";
014
015 FILE *fInput;
016 char szLine[512];
017 int i = 0, j, nMaxj, nDist, nPos, nPos1, bAchouDados = 0;
018 long lFilePos;
019
020
021 fInput = fopen(szFName, "r");
022 if (!fInput) return 0;
023
024
025 memset(PcvData->anDist, 0, sizeof(PcvData->anDist));
026 PcvData->nDistDelta = 0;
027
028
029 nMaxj = (PcvData->nNumVertices <= 0 ? MAX_VERTICES :
030 PcvData->nNumVertices);
031
032
033
034 while (!feof(fInput) && !bAchouDados) {
035 lFilePos = ftell(fInput);
036 fgets(szLine, sizeof(szLine), fInput);
037 if (strncasecmp(szLine, szDataDelim, strlen(szDataDelim)) == 0) {
038 bAchouDados = 1;
039 } else if (isdigit(szLine[0])) {
040 fseek(fInput, lFilePos, SEEK_SET);
041 bAchouDados = 1;
042 }
043 }
044
045
046 if (feof(fInput)) {
047 fclose(fInput);
048 return 0;
049 }
050
051
052 while (!feof(fInput)) {
053 nPos = 0;
054 j = i + 1;
055
056
057 fgets(szLine, sizeof(szLine), fInput);
058
059
060 while ((j < nMaxj) && (sscanf(szLine + nPos, "%d%n", &nDist, &nPos1) > 0)) {
061 nPos += nPos1;
062 PcvData->anDist[i][j] = nDist;
063 PcvData->anDist[j][i] = nDist;
064
065
066 if (nDist > PcvData->nDistDelta) PcvData->nDistDelta = nDist;
067
068 j++;
069 }
070
071
072 if ((i == 0) && (PcvData->nNumVertices <= 0)) {
073 PcvData->nNumVertices = j;
074 nMaxj = PcvData->nNumVertices;
075 }
076 i++;
077 }
078
079
080
081 for (i = 0; i < PcvData->nNumVertices; i++) {
082 for (j = 0; j < PcvData->nNumVertices; j++) {
083 if (i != j) PcvData->anDist[i][j] += PcvData->nDistDelta;
084 }
085 }
086
087
088 fclose(fInput);
089 return 1;
090 }
091
092
093
094 void writeOutput(const TPcvData *PcvData)
095 {
096 int i;
097
098
099 for (i = 0; i < PcvData->nNumVertices; i++) {
100 printf("%d\n", PcvData->anMinCaminho[i]);
101 }
102 }
Seguinte: fbruta.h
Acima: Códigos-fonte: Solução por força
Anterior: inout.h
VilarNt
2003-06-20