Exemple #1
0
/*
 *  Function:
 *    writeEntryFile
 *
 *  Description:
 *    Writes the entries from a linked list to a file.
 *
 *  Arguments:
 *    Pointer to the first node of the linked list:
 *      LinkedList * lp
 *    Pointer to the file stream:
 *      FILE * fp
 *
 *  Return value:
 *    None.
 */
void writeEntryFile(LinkedList * lp, FILE *fp)
{
  LinkedList * aux;

  aux = lp;
  while(aux != NULL)
  {
    printEntry((Entry *) getItemLinkedList(aux), fp);
    aux = getNextNodeLinkedList(aux);
  }
}
Exemple #2
0
ListNode * HandleRest(ListNode * resthead, ParkingLot * parkinglot, int timeunit, FILE * outputfile)
{
      Rest * rest;
      ListNode * aux;
      int i=0;
      /*Get the head of the restricion list to the aux pointer for the first while comparation*/
      aux = resthead;

      if(aux == NULL)
        return NULL;

      /*Get the first restriction*/
      rest = (Rest*) getItemLinkedList(aux);

      while(aux != NULL && GetRestTime(rest) == timeunit)
      {
          if(GetRestFlag(rest) == 'p')
          {
            i = FindIP(GetVertices(parkinglot), GetRestCoord(rest, 'x'), GetRestCoord(rest, 'y'), GetRestCoord(rest, 'z'), GetDecoder(parkinglot) );

            if(GetIP_Flagres(i, GetDecoder(parkinglot) ) == 1)
             {
                 ReleasePos(i, GetDecoder(parkinglot) );
                 IncFreeSpots(parkinglot);
                if( GetFreeSpots(parkinglot) != 0)
                  HandleQueue(parkinglot, outputfile, timeunit);
              }
            else
            {
                RestrictPos(i, GetDecoder(parkinglot) );
                DecFreeSpots(parkinglot);
            }
          }
          else if(GetRestFlag(rest) == 'f')
          {
            if( IsFloorRestricted( GetRestCoord(rest, 'z'), parkinglot ) )
            {
            	ReleaseWholeFloor(i, parkinglot ); /* la dento temos de fazer bue release spots */
              if( GetFreeSpots(parkinglot) != 0)
           			HandleQueue(parkinglot, outputfile, timeunit);
            }
            else
              RestrictWholeFloor( GetRestCoord(rest, 'z'), parkinglot );
          }


        aux = getNextNodeLinkedList(aux);
        rest = (Rest*) getItemLinkedList(aux);
      }

      /*Return the new head of the linked list*/
      return aux;

}
Exemple #3
0
void PrintPath(FILE * outputfile, ListNode * carpath, ListNode * footpath, char * carname, int entrytime, ParkingLot * parkinglot, int pathweight)
{

    ListNode * carpathaux, * footpathaux;
    int x = 0, y = 0, z = 0, time = -1, timecompare, px = -1, py = -1, pz = -1; /*px, py, px are the coordenates that resulted from the previous iteration*/
    int position, parkingtime;
    Array decoder = GetDecoder(parkinglot);
    char direction = 'a', pdirection = 'a';

    carpathaux = carpath;

    position = *( (int*) getItemLinkedList(carpathaux) );
    px = GetIP_Coord(position, 'x', decoder);
    py = GetIP_Coord(position, 'y', decoder);
    pz = GetIP_Coord(position, 'z', decoder);

    for( carpathaux = getNextNodeLinkedList(carpathaux); carpathaux !=NULL; carpathaux = getNextNodeLinkedList(carpathaux) )
    {
        time++;

        position = *( (int*) getItemLinkedList(carpathaux) );
        x = GetIP_Coord(position, 'x', decoder);
        y = GetIP_Coord(position, 'y', decoder);
        z = GetIP_Coord(position, 'z', decoder);

        if( (x - px) != 0 )
            direction = 'x';
        else if( (y - py) != 0 )
            direction = 'y';
        else if( (z - pz) != 0 )
            direction = 'z';

        /*We dont write to the file in the first iteration after the car leaves the entry, but we need to find the direction*/
        if( direction != pdirection && time != 0)
        {

            escreve_saida( outputfile, carname, entrytime + time, px , py , pz, 'm');

            if(GetIP_Type(position, decoder) == 'u' || GetIP_Type(position, decoder) == 'd')
                time++;
        }

        px = x;
        py = y;
        pz = z;
        pdirection = direction;
    }

    time++;

    timecompare = time;

    parkingtime = entrytime + time;
    escreve_saida( outputfile, carname, entrytime + time, px, py, pz, 'e');
    AddParkedCar(carname, x, y, z, parkinglot);

    time--;

    for( footpathaux = footpath; footpathaux !=NULL; footpathaux = getNextNodeLinkedList(footpathaux) )
    {
        time++;

        position = *( (int*) getItemLinkedList(footpathaux) );
        x = GetIP_Coord(position, 'x', decoder);
        y = GetIP_Coord(position, 'y', decoder);
        z = GetIP_Coord(position, 'z', decoder);

        if( (x - px) != 0 )
            direction = 'x';
        else if( (y - py) != 0 )
            direction = 'y';
        else if( (z - pz) != 0 )
            direction = 'z';

        if( (direction != pdirection && time != timecompare) || (time == timecompare+1) )
        {
            escreve_saida( outputfile, carname, entrytime + time, px , py , pz, 'p');

            if(GetIP_Type(position, decoder) == 'u' || GetIP_Type(position, decoder) == 'd')
                time++;
        }


        px = x;
        py = y;
        pz = z;
        pdirection = direction;
    }

    time++;

    escreve_saida( outputfile, carname, entrytime + time, px, py, pz, 'a');

    /*Writes the balance of the path*/
    escreve_saida( outputfile, carname, entrytime, parkingtime, entrytime + time, pathweight, 'x');

}