本文整理汇总了C++中Sim::getWaitTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Sim::getWaitTime方法的具体用法?C++ Sim::getWaitTime怎么用?C++ Sim::getWaitTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sim
的用法示例。
在下文中一共展示了Sim::getWaitTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pp
// Preemptive Priority (PP)
void pp(Sim* p, int size)
{
int tempWait = 0, minTurn = p[0].getTurnTime(), maxTurn = 0, turnT = 0, minInitial = p[0].getITime(),
maxInitial = 0, initialT = 0, minWait = p[0].getWaitTime(), maxWait = 0, totalW = 0;
vector <Sim> arrived; //vector to store processes that has arrived
int counter = 0;
int store = 0;
bool firstTime = true;
elapsedTime = 0;
cout << "\n\n\nPreemptive-Priority | Send Processes to CPU and run: \n";
//push process into the vector if the arrival time is 0
for (int i = 0; i < size; i++)
{
if (p[i].getATime() == 0)
{
arrived.push_back(p[i]);
}
}
//Sort "arrived" by priority
sortPriority(arrived);
while(counter != size)
{
int checkArrival;
int timeShortest = 8000;
bool found = false;
Sim temp = arrived[0];
for (int i = 0; i < size; i++)
{
checkArrival = arrived[0].getTimeRemain() + elapsedTime;
if (checkArrival > p[i].getATime())
{
if(p[i].getATime() < timeShortest)
{
timeShortest = p[i].getATime();
}
found = true;
}
}
if(found == true)
{
arrived[0].setTimeRemain(elapsedTime - arrived[0].getcTime()); // set the remain time for current process
elapsedTime = elapsedTime - arrived[0].getTimeRemain();
for(int i = 0; i < size; i ++)
{
if(p[i].getATime() == timeShortest)
{
arrived.push_back(p[i]);
}
}
sortPriority(arrived);
}
else // the process has terminated before any other process entered
{
arrived[0].setTimeRemain(0);
temp = arrived[0];
arrived.erase(arrived.begin());
sortPriority(arrived);
elapsedTime+=temp.getTimeRemain(); // final elapsed time after this process terminates
temp.setTurnTime(elapsedTime);
printTerminate(elapsedTime, temp.getpId(), temp.getTurnTime(), temp.getWaitTime());
counter++;
}
if (!firstTime && !arrived.empty( ))
{
elapsedTime = totalElapsedTime(elapsedTime);
printContextSwitch(elapsedTime, temp.getpId(), arrived[0].getpId());
elapsedTime = totalElapsedTime(elapsedTime);
}
firstTime = false;
}
}
示例2: sjf
/* Shortest-Job First (SFS)
* This will sort the processes that are sent in based on the
* shortest job in the array. */
void sjf(Sim* p, int size)
{
int tempWait = 0, minTurn = p[0].getTurnTime(), maxTurn = 0,
turnT = 0, minInitial = p[0].getITime(), maxInitial = 0,
initialT = 0, minWait = p[0].getWaitTime(), maxWait = 0,
totalW = 0;
elapsedTime = 0;
vector <Sim> arrived;
int check = 1;
//push it into vector if it arrives at time 0
for(int i = 0; i < size; i++)
{
if (p[i].getATime() == 0)
{
arrived.push_back(p[i]);
check = i + 1;
}
}
sort(arrived.begin(), arrived.end(), compareCPU);
cout << "\n\n\nShortest Job First without Preemption | Send Processes to CPU and run: \n";
//for(int j = 0; j < size; j++)
int counter = 0;
bool firstTime = true;
Sim temp;
while(counter != size)
{
for(int i = check; i < size; i++)
{
int totalTime = arrived[0].getcTime() + elapsedTime;
if (totalTime > p[i].getATime())
{
arrived.push_back(p[i]);
check = i + 1;
}
}
temp = arrived[0];
arrived.erase(arrived.begin()); // this process will have terminated so it can be removed from the vector
sort(arrived.begin(), arrived.end(), compareCPU); // sorts all the processes that will be in the vector after the one terminates
temp.setWaitTime(elapsedTime);
printFirst(elapsedTime, temp.getpId(), temp.getWaitTime());
elapsedTime+=temp.getcTime();
temp.setTurnTime(elapsedTime);
printTerminate(elapsedTime, temp.getpId(), temp.getTurnTime(), temp.getWaitTime());
firstTime = false;
counter ++;
if (!firstTime && !arrived.empty( ))
{
elapsedTime = totalElapsedTime(elapsedTime);
printContextSwitch(elapsedTime, temp.getpId(), arrived[0].getpId());
elapsedTime = totalElapsedTime(elapsedTime);
}
}
dataToCollect(p, size, minTurn, maxTurn, turnT, minInitial, maxInitial, initialT, minWait, maxWait, totalW);
}