Exemplo n.º 1
0
void Day::nextCrash()
{
    for(int i = 0; i < getMachines().size(); i++)
    {
        float workTime = randExp(machines[i].getWorkMeanTime());
        machines[i].setTempWorkTime(workTime);
    }

    qSort(machines.begin(), machines.end(), lessThan);
    int i = 0;
    Machine tmpMachine;
    while(machines[0].getInactionTime() + machines[0].getWorkTime() < 15.99
          || machines[1].getInactionTime() + machines[1].getWorkTime() < 15.99
          || machines[2].getInactionTime() + machines[2].getWorkTime() < 15.99)
    {
        calculate(i);
        machines[0].setTempWorkTime(randExp(machines[0].getWorkMeanTime()));
        qSort(machines.begin(), machines.end(), lessThan);
        if(machines[0].getFinished())
            for(int j = 1; j <= 2; j++)
            {
                if(!machines[j].getFinished())
                {
                    tmpMachine = machines[j];
                    machines[j] = machines[0];
                    machines[0] = tmpMachine;
                    break;
                }
            }

        i++;
    }
}
Exemplo n.º 2
0
float Day::calculateProfit()
{
   float profit = 0;
   for(int i = 0; i < 3; i++)
      profit += getMachines()[i].getWorkTime() * getMachines()[i].getProfit() -
                getMachines()[i].getInactionTime() * getMachines()[i].getLoss() -
                getMachines()[i].getRepairTime() * getWorker6()->getCost() -
                getMachines()[i].getRepairTime() * getWorker3()->getCost();
   return profit;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
struct dyString *dy = NULL;
int startPos = 1;
char *chrom = "chr1";
int chromSize = 0;
int windowSize = 100000;
struct machine *machinePos;
time_t now;
char testTime[100];
char testDate[100];
long elapsedTime = 0;

optionInit(&argc, argv, optionSpecs);

expireSeconds = 300;	/* 5 minutes */
(void) signal(SIGALRM, selfApoptosis);
(void) alarm(expireSeconds);	/* CGI timeout */

quiet = optionExists("quiet");
now = time(NULL);
strftime(testTime, 100, "%H:%M", localtime(&now));
strftime(testDate, 100, "%B %d, %Y", localtime(&now));
if (!quiet)
    printf("%s %s\n", testDate, testTime);

if (argc != 2)
    usage();

srand( (unsigned) time(NULL) );

database = hDefaultDbForGenome(NULL); // default human db

chromHash = loadAllChromInfo();
chromSize = getChromSize(chrom);
startPos = getStartPos(chromSize, windowSize);
if (! quiet)
    printf("%s %s:%d-%d\n\n", database, chrom, startPos, startPos + windowSize);

getMachines(argv[1]);

for (machinePos = machineList; machinePos != NULL; machinePos = machinePos->next)
    {
    dy = newDyString(256);
    dyStringPrintf(dy, "%s/cgi-bin/hgTracks?db=%s&position=%s:%d-%d", machinePos->name, 
                   database, chrom, startPos, startPos + windowSize);
    elapsedTime = hgTracksRandom(dy->string);
    if (quiet)
	{
	printf("%ld\n", elapsedTime);
	}
    else
	{
	if (elapsedTime > 5000)
	    printf("%s %ld <---\n", machinePos->name, elapsedTime);
	else
	    printf("%s %ld\n", machinePos->name, elapsedTime);
	}
    }
if (! quiet)
    printf("----------------------------------\n");

/* free machine list */
return 0;
}
Exemplo n.º 4
0
void Day::calculate(int row)
{

    float workTime = getMachines()[0].getWorkTime();            //Общее время работы
    float tempWorkTime = getMachines()[0].getTempWorkTime();   //Длительность текущей работы
    float inactionTime = getMachines()[0].getInactionTime();    //Общее время простоя


    ///Прибавил время работы машины
    /// проверил

    float currentTime = workTime + inactionTime + tempWorkTime;  //День
    if(currentTime > 16)                                        //Отработал больше 16 часов
    {
        machines[0].setWorkTime(workTime + tempWorkTime - (currentTime - 16));

        tableDataCreated(row, 0, getMachines()[0].getType()); //ЗАНЕСЕНИЕ В ТАБЛИЦУ
        tableDataCreated(row, 1, QString::number(getMachines()[0].getTempWorkTime()));
        tableDataCreated(row, 2, QString::number(workTime + inactionTime));
        tableDataCreated(row, 3, QString::number(getMachines()[0].getWorkTime() + inactionTime));
        tableDataCreated(row, 8, QString::number(getMachines()[0].getWorkTime()));
        tableDataCreated(row, 9, QString::number(round(getMachines()[0].getRepairTime())));
        tableDataCreated(row, 10, QString::number(round(getMachines()[0].getInactionTime())));
        machines[0].setFinished(true);
        return;
    }
    else
    {
        machines[0].setWorkTime(workTime + tempWorkTime);

        tableDataCreated(row, 0, getMachines()[0].getType());
        tableDataCreated(row, 1, QString::number(round(getMachines()[0].getTempWorkTime())));
        tableDataCreated(row, 2, QString::number(round(workTime + inactionTime)));
        tableDataCreated(row, 3, QString::number(round(getMachines()[0].getWorkTime() + inactionTime)));
        tableDataCreated(row, 8, QString::number(round(getMachines()[0].getWorkTime())));
    }


    /// Прибавил время простоя

    float max = 0;
    for(int i = 1; i < getMachines().size(); i++)
    {
        float lastRepairTime = machines[i].getLastRepairTime();       //Время конца предыдущего ремонта
        if(lastRepairTime > currentTime && lastRepairTime > max)
        {
            max = lastRepairTime;
        }
    }

    float newInactionTime = 0;

    /// проверил
    if(max > 16)
    {
        newInactionTime = (max - currentTime) - (max - 16);
        tableDataCreated(row, 4, QString::number(round(newInactionTime)));
        machines[0].setInactionTime(inactionTime + newInactionTime); //Вычитаем всё, что вылезло
        tableDataCreated(row, 10, QString::number(round(getMachines()[0].getInactionTime())));
        machines[0].setFinished(true);
        return;
    }
    else if(max > 0)
    {
        newInactionTime = max - currentTime;
        tableDataCreated(row, 4, QString::number(round(newInactionTime)));
        machines[0].setInactionTime(inactionTime + newInactionTime);
       // tableDataCreated(row, 10, QString::number(round(getMachines()[0].getInactionTime())));
        currentTime = max;
    }



    /// Разыграл время ремонта

    float repairTempTime = randExp(machines[0].getRepairMeanTime());
    tableDataCreated(row, 5, QString::number(round(repairTempTime)));

    /// Прибавил время ремонта + время работы слесарей

    machines[0].setRepairTime(getMachines()[0].getRepairTime() + repairTempTime);
    getWorker3()->setWorkTime(getWorker3()->getWorkTime() + repairTempTime);
    getWorker6()->setWorkTime(getWorker6()->getWorkTime() + repairTempTime);
    machines[0].setLastRepairTime(currentTime + repairTempTime);
    tableDataCreated(row, 6, QString::number(round(currentTime)));

    ///ПРОВЕРИЛ

    currentTime += repairTempTime;
    if(currentTime > 16)
    {
        machines[0].setInactionTime(machines[0].getInactionTime() + repairTempTime
                                    - (currentTime - 16)); //Убавил время простоя
        machines[0].setFinished(true);
    }
    else
    {
        machines[0].setInactionTime(getMachines()[0].getInactionTime() + repairTempTime);
    }
    tableDataCreated(row, 9, QString::number(round(getMachines()[0].getRepairTime())));
    tableDataCreated(row, 7, QString::number(round(currentTime)));
    tableDataCreated(row, 10, QString::number(round(getMachines()[0].getInactionTime())));

}