ReadPenalties.c
Go to the documentation of this file.
1 #include "LKH.h"
2 
3 /*
4  * The ReadPenalties function attempts to read node penalties (Pi-values)
5  * from file.
6  *
7  * The first line of the file contains the number of nodes.
8  *
9  * Each of the following lines is of the form
10  * <integer> <integer>
11  * where the first integer is a node number, and the second integer
12  * is the Pi-value associated with the node.
13  *
14  * If reading succeeds, the function returns 1; otherwise 0.
15  *
16  * The function is called from the CreateCandidateSet function.
17  */
18 
20 {
21  int i, Id;
22  Node *Na, *Nb = 0;
23  static int PenaltiesRead = 0;
24 
25  if (PiFileName == 0)
26  return 0;
27  if (PenaltiesRead || strcmp(PiFileName, "0") == 0)
28  return PenaltiesRead = 1;
29  if (!(PiFile = fopen(PiFileName, "r")))
30  return 0;
31  if (TraceLevel >= 1)
32  printff("Reading PI_FILE: \"%s\" ... ", PiFileName);
33  fscanint(PiFile, &i);
34  if (i != Dimension)
35  eprintf("PI_FILE \"%s\" does not match problem", PiFileName);
36  fscanint(PiFile, &Id);
37  assert(Id >= 1 && Id <= Dimension);
38  FirstNode = Na = &NodeSet[Id];
39  fscanint(PiFile, &Na->Pi);
40  for (i = 2; i <= Dimension; i++) {
41  fscanint(PiFile, &Id);
42  assert(Id >= 1 && Id <= Dimension);
43  Nb = &NodeSet[Id];
44  fscanint(PiFile, &Nb->Pi);
45  Nb->Pred = Na;
46  Na->Suc = Nb;
47  Na = Nb;
48  }
49  FirstNode->Pred = Nb;
50  Nb->Suc = FirstNode;
51  fclose(PiFile);
52  if (TraceLevel >= 1)
53  printff("done\n");
54  return PenaltiesRead = 1;
55 }
int Dimension
Definition: LKH.h:190
int fscanint(FILE *f, int *v)
Definition: fscanint.c:13
void printff(char *fmt,...)
Definition: printff.c:10
Definition: LKH.h:68
int ReadPenalties()
Definition: ReadPenalties.c:19
Node * NodeSet
Definition: LKH.h:235
Node * Pred
Definition: LKH.h:89
Node * Suc
Definition: LKH.h:89
Node * FirstNode
Definition: LKH.h:201
int TraceLevel
Definition: LKH.h:274
void eprintf(const char *fmt,...)
Definition: eprintf.c:8
char * PiFileName
Definition: LKH.h:284
FILE * PiFile
Definition: LKH.h:302
int Pi
Definition: LKH.h:83


glkh_solver
Author(s): Francisco Suarez-Ruiz
autogenerated on Mon Jun 10 2019 13:50:27