Skip to content

Commit

Permalink
Add arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
vldtecno committed Mar 24, 2024
1 parent 1e5fc87 commit 8d78871
Show file tree
Hide file tree
Showing 124 changed files with 4,493 additions and 4,483 deletions.
4 changes: 2 additions & 2 deletions Doc/Doxygen/FullDocumentation.doxy
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ CREATE_SUBDIRS_LEVEL = 8
# U+3044.
# The default value is: NO.

ALLOW_UNICODE_NAMES = NO
ALLOW_UNICODE_NAMES = YES

# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
Expand Down Expand Up @@ -395,7 +395,7 @@ AUTOLINK_SUPPORT = YES
# diagrams that involve STL classes more complete and accurate.
# The default value is: NO.

BUILTIN_STL_SUPPORT = NO
BUILTIN_STL_SUPPORT = YES

# If you use Microsoft's C++/CLI language, you should set this option to YES to
# enable parsing support.
Expand Down
3 changes: 1 addition & 2 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
cmake_minimum_required (VERSION 3.8)

add_subdirectory(Factorial)
add_subdirectory(PhoneMenu)
add_subdirectory(Elevator)
if(BUILD_IMPORT_EXPORT)
add_subdirectory(PhoneMenuXML)
add_subdirectory(PhoneMenu)
endif(BUILD_IMPORT_EXPORT)
102 changes: 42 additions & 60 deletions Examples/Elevator/Controller/ElevatorController.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of PTN Engine
*
* Copyright (c) 2017-2023 Eduardo Valgôde
* Copyright (c) 2017-2024 Eduardo Valgôde
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@

#include "Controller/ElevatorController.h"
#include "Controller/ElevatorPetriNet.h"

#include <algorithm>
#include <iostream>
#include <mutex>
Expand All @@ -43,30 +42,13 @@ void printFloorList(const unordered_set<int> &floors)
} // namespace

ElevatorController::ElevatorController()
: m_pPetriNet(nullptr)
, m_currentFloor(s_bottomFloor)
: m_currentFloor(s_bottomFloor)
, m_toAddToDestination(s_bottomFloor)
, m_destinations()
, m_nextTravelDestinations()
, m_floorsWaitingToGoUp()
, m_floorsWaitingToGoDown()
{
m_pPetriNet = make_unique<ElevatorPetriNet>(*this);
m_pPetriNet->execute(false);
}

ElevatorController::~ElevatorController()
{
}

void ElevatorController::checkPetriNetPointer() const
{
if (m_pPetriNet == nullptr)
{
throw runtime_error("Petri net not available.");
}
}

void ElevatorController::openDoors()
{
m_pPetriNet->openDoors();
Expand All @@ -80,7 +62,7 @@ void ElevatorController::closeDoors()
bool ElevatorController::callElevatorUp(const int floor)
{
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
if (floor < s_bottomFloor || floor >= s_topFloor)
{
return false;
Expand All @@ -94,7 +76,7 @@ bool ElevatorController::callElevatorUp(const int floor)
bool ElevatorController::callElevatorDown(const int floor)
{
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
if (floor <= s_bottomFloor || floor > s_topFloor)
{
return false;
Expand All @@ -108,7 +90,7 @@ bool ElevatorController::callElevatorDown(const int floor)
bool ElevatorController::setDestinationFloor(const int floor)
{
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
if (floor < s_bottomFloor || floor > s_topFloor)
{
return false;
Expand All @@ -127,15 +109,15 @@ void ElevatorController::stop()
// Actions
void ElevatorController::addDestination1()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
m_nextTravelDestinations.erase(m_toAddToDestination);
m_destinations.insert(m_toAddToDestination);
printDestinations();
}

void ElevatorController::addDestination2()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
if (m_destinations.contains(m_toAddToDestination))
{
return;
Expand All @@ -150,14 +132,14 @@ void ElevatorController::addDestination2()

void ElevatorController::addWaitingToGoDown()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
m_floorsWaitingToGoDown.insert(m_toAddToDestination);
printWaitingGoDown();
}

void ElevatorController::addWaitingToGoUp()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
m_floorsWaitingToGoUp.insert(m_toAddToDestination);
printWaitingGoUp();
}
Expand All @@ -176,7 +158,7 @@ void ElevatorController::removeDestinationGD()

void ElevatorController::removeDestination()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Removed " << m_currentFloor << " from destinations" << endl;
auto it = m_destinations.find(m_currentFloor);
if (it != m_destinations.end())
Expand All @@ -187,7 +169,7 @@ void ElevatorController::removeDestination()

void ElevatorController::removeCurrentFromWaitingToGoDown()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
size_t i = m_floorsWaitingToGoDown.erase(m_currentFloor);
if (i > 0)
{
Expand All @@ -197,7 +179,7 @@ void ElevatorController::removeCurrentFromWaitingToGoDown()

void ElevatorController::removeCurrentFromWaitingToGoUp()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
size_t i = m_floorsWaitingToGoUp.erase(m_currentFloor);
if (i > 0)
{
Expand All @@ -207,41 +189,41 @@ void ElevatorController::removeCurrentFromWaitingToGoUp()

void ElevatorController::rotateLists()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
swap(m_destinations, m_nextTravelDestinations);
m_destinations.erase(m_currentFloor);
}

void ElevatorController::increaseFloor()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Ascending... " << endl;
++m_currentFloor;
printCurrentFloor();
}

void ElevatorController::decreaseFloor()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Descending... " << endl;
--m_currentFloor;
printCurrentFloor();
}

void ElevatorController::mergeGoingUpGTCurrent()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
mergeToDestinations(m_floorsWaitingToGoDown, false);
}

void ElevatorController::mergeMinGoingUp()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
if (m_floorsWaitingToGoUp.empty())
{
return;
}
const int minWaiting = *min_element(m_floorsWaitingToGoUp.begin(), m_floorsWaitingToGoUp.end());
const int minWaiting = *ranges::min_element(m_floorsWaitingToGoUp.begin(), m_floorsWaitingToGoUp.end());
m_destinations.insert(minWaiting);
m_floorsWaitingToGoUp.erase(minWaiting);

Expand All @@ -251,12 +233,12 @@ void ElevatorController::mergeMinGoingUp()

void ElevatorController::mergeMaxGoingDown()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
if (m_floorsWaitingToGoDown.empty())
{
return;
}
const int maxWaiting = *max_element(m_floorsWaitingToGoDown.begin(), m_floorsWaitingToGoDown.end());
const int maxWaiting = *ranges::max_element(m_floorsWaitingToGoDown.begin(), m_floorsWaitingToGoDown.end());
m_destinations.insert(maxWaiting);
m_floorsWaitingToGoDown.erase(maxWaiting);

Expand All @@ -266,7 +248,7 @@ void ElevatorController::mergeMaxGoingDown()

void ElevatorController::mergePostponedToCurrent()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
m_destinations.insert(m_nextTravelDestinations.begin(), m_nextTravelDestinations.end());
m_nextTravelDestinations.clear();

Expand All @@ -275,7 +257,7 @@ void ElevatorController::mergePostponedToCurrent()

void ElevatorController::mergeGoingDownSTCurrent()
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
mergeToDestinations(m_floorsWaitingToGoDown, true);
}

Expand All @@ -286,7 +268,7 @@ void ElevatorController::mergeToDestinations(unordered_set<int> &toAdd, const bo
{
deleted = false;
auto floorIt =
std::find_if(toAdd.cbegin(), toAdd.cend(),
ranges::find_if(toAdd.cbegin(), toAdd.cend(),
[this, &lessThan](const int floor)
{ return (lessThan && floor < m_currentFloor) || (!lessThan && floor > m_currentFloor); });
if (floorIt != toAdd.cend())
Expand All @@ -313,7 +295,7 @@ bool ElevatorController::isFloorNotInList() const

bool ElevatorController::isFloorInList() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
return m_destinations.contains(m_currentFloor);
}

Expand All @@ -324,69 +306,69 @@ bool ElevatorController::isDestinationListNotEmpty() const

bool ElevatorController::isDestinationListEmpty() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
return m_destinations.empty();
}

bool ElevatorController::isMarkedFloorNotCurrentFloor() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
return m_toAddToDestination != m_currentFloor;
}

bool ElevatorController::isMarkedFloorGreaterThanCurrentFloor() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
return m_toAddToDestination > m_currentFloor;
}

bool ElevatorController::isMarkedFloorSmallerThanCurrentFloor() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
return m_toAddToDestination < m_currentFloor;
}

bool ElevatorController::isMinSmallerThanCurrent() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
if (m_destinations.empty())
{
return false;
}
int minFloor = *min_element(m_destinations.cbegin(), m_destinations.cend());
int minFloor = *ranges::min_element(m_destinations.cbegin(), m_destinations.cend());
return minFloor < m_currentFloor;
}

bool ElevatorController::isMinGreaterThanCurrent() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
if (m_destinations.empty())
{
return false;
}
int minFloor = *min_element(m_destinations.cbegin(), m_destinations.cend());
int minFloor = *ranges::min_element(m_destinations.cbegin(), m_destinations.cend());
return minFloor > m_currentFloor;
}

bool ElevatorController::isMaxSmallerThanCurrent() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
if (m_destinations.empty())
{
return false;
}
int maxFloor = *max_element(m_destinations.cbegin(), m_destinations.cend());
int maxFloor = *ranges::max_element(m_destinations.cbegin(), m_destinations.cend());
return maxFloor < m_currentFloor;
}

bool ElevatorController::isMaxGreaterThanCurrent() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
if (m_destinations.empty())
{
return false;
}
int maxFloor = *max_element(m_destinations.cbegin(), m_destinations.cend());
int maxFloor = *ranges::max_element(m_destinations.cbegin(), m_destinations.cend());
return maxFloor > m_currentFloor;
}

Expand All @@ -395,7 +377,7 @@ bool ElevatorController::isMaxGreaterThanCurrent() const

void ElevatorController::elevatorStopped() const
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Elevator stopped" << endl;
}

Expand All @@ -406,25 +388,25 @@ void ElevatorController::elevatorMoving() const

void ElevatorController::doorsAreOpen() const
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Elevator doors are open" << endl;
}

void ElevatorController::doorsAreClosed() const
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Elevator doors are closed" << endl;
}

void ElevatorController::goingUp() const
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Scheduled to go up." << endl;
}

void ElevatorController::goingDown() const
{
unique_lock<shared_mutex> l(m_mutex);
unique_lock l(m_mutex);
cout << "Scheduled to go down." << endl;
}

Expand Down Expand Up @@ -459,7 +441,7 @@ void ElevatorController::printWaitingGoUp() const

void ElevatorController::printSchedule() const
{
shared_lock<shared_mutex> l(m_mutex);
shared_lock l(m_mutex);
cout << endl;
cout << "Scheduled floors: " << endl;
printDestinations();
Expand Down
Loading

0 comments on commit 8d78871

Please sign in to comment.