Exemple #1
0
void Sudoku::swapRowLine()
{
	int a, b;
	chooseLine(a, b);
	int temp[size];
	memcpy(temp, qmap[a], sizeof(temp));
	memcpy(qmap[a], qmap[b], sizeof(temp));
	memcpy(qmap[b], temp, sizeof(temp));
}
Exemple #2
0
void Sudoku::swapColLine()
{
	int a, b;
	chooseLine(a, b);
	int temp[size];
	for(int j=0; j<size; j++)
	{
		temp[j] = qmap[j][a];
		qmap[j][a] = qmap[j][b];
		qmap[j][b] = temp[j];
	}
}
Exemple #3
0
void Controller::multToMultAlgorithm()
{
        //1 loop = 1 minute
    for (int i = 0; i <= 480; i++)
    {
        //max of two new additions available
        Customer newCustomer1;
        Customer newCustomer2;

        //people enter the line
        int peopleGoToLine = rand() % 3; //0-2 people enter every minute

        switch(peopleGoToLine)
        {
        case 0: //add zero people
            break;
        case 1: //add one person
            if (simType == 2) //random times
            {
                newCustomer1.serviceTime = (rand() % 4) + 1; //new time
            }
            else if (simType == 3)
            {
                newCustomer1.cart = rand() % 10; //0 - 9 items added to the cart
                newCustomer1.serviceTime += newCustomer1.cart; //new service time
            }

            //add the customer to the line with the least amount of people
            switch(chooseLine())
            {
            case 1:
                line1.push_back(newCustomer1); //add customer to the line
                break;
            case 2:
                line2.push_back(newCustomer1); //add customer to the line
                break;
            case 3:
                line3.push_back(newCustomer1); //add customer to the line
                break;
            }
            break;
        case 2:
            if (simType == 2) //random times
            {
                newCustomer1.serviceTime = (rand() % 4) + 1; //new time
                newCustomer2.serviceTime = (rand() % 4) + 1; //new time
            }
            else if (simType == 3)
            {
                newCustomer1.cart = rand() % 10; //0 - 9 items added to the cart
                newCustomer1.serviceTime += newCustomer1.cart; //new service time
                newCustomer2.cart = rand() % 10; //0 - 9 items added to the cart
                newCustomer2.serviceTime += newCustomer1.cart; //new service time
            }

            //add the customer1 to the line with the least amount of people
            switch(chooseLine())
            {
            case 1:
                line1.push_back(newCustomer1); //add customer to the line
                break;
            case 2:
                line2.push_back(newCustomer1); //add customer to the line
                break;
            case 3:
                line3.push_back(newCustomer1); //add customer to the line
                break;
            }

            //add the customer2 to the line with the least amount of people
            switch(chooseLine())
            {
            case 1:
                line1.push_back(newCustomer2); //add customer to the line
                break;
            case 2:
                line2.push_back(newCustomer2); //add customer to the line
                break;
            case 3:
                line3.push_back(newCustomer2); //add customer to the line
                break;
            }
            break;
        }

        //now run the algorithm
        if (line1.size() > 0) //if there are any customers in the line, do the algorithm
        {
            //increase time for everyone by 1
            for(int j = 0; j < line1.size(); j++)
            {
                line1.at(j).totalTime++;
            }
            //if the new time is the greatest, replace the integer
            if (line1.front().totalTime > greatestWait)
            {
                greatestWait = line1.front().totalTime;
            }
            if (line1.front().serviceTime <= 0) //if the first person is done, remove them
            {
                timeTotal += line1.front().totalTime;
                totalCustomers++;

                //re-arrange the vector
                line1.erase(line1.begin(),line1.begin()+1);
            }
            line1.front().serviceTime--; //decrement time of the person in the front of the line1
        }
        if (line2.size() > 0)
        {
            //increase time for everyone by 1
            for(int j = 0; j < line2.size(); j++)
            {
                line2.at(j).totalTime++;
            }
            //if the new time is the greatest, replace the integer
            if (line2.front().totalTime > greatestWait)
            {
                greatestWait = line2.front().totalTime;
            }
            if (line2.front().serviceTime <= 0) //if the first person is done, remove them
            {
                timeTotal += line2.front().totalTime;
                totalCustomers++;

                //re-arrange the vector
                line2.erase(line2.begin(),line2.begin()+1);
            }
        line2.front().serviceTime--; //decrement time of the person in the front of the line2
        }
        if (line3.size() > 0)
        {
            //increase time for everyone by 1
            for(int j = 0; j < line3.size(); j++)
            {
                line3.at(j).totalTime++;
            }
            //if the new time is the greatest, replace the integer
            if (line3.front().totalTime > greatestWait)
            {
                greatestWait = line3.front().totalTime;
            }
            if (line3.front().serviceTime <= 0) //if the first person is done, remove them
            {
                timeTotal += line3.front().totalTime;
                totalCustomers++;

                //re-arrange the vector
                line3.erase(line3.begin(),line3.begin()+1);
            }
            line3.front().serviceTime--; //decrement time of the person in the front of the line3
        }

            if (i == 30) //30 minutes have passed
            {
                string totalCus = intToStr(totalCustomers);
                string avgWait = intToStr(timeTotal/totalCustomers);
                string gr8estWait = intToStr(greatestWait);
                min30 = " " + totalCus + "; " + avgWait + "; " + gr8estWait;
            }
            if (i == 60) //60 minutes have passed
            {
                string totalCus = intToStr(totalCustomers);
                string avgWait = intToStr(timeTotal/totalCustomers);
                string gr8estWait = intToStr(greatestWait);
                min60 = " " + totalCus + "; " + avgWait + "; " + gr8estWait;
            }
            if (i == 120) //120 minutes have passed
            {
                string totalCus = intToStr(totalCustomers);
                string avgWait = intToStr(timeTotal/totalCustomers);
                string gr8estWait = intToStr(greatestWait);
                min120 = " " + totalCus + "; " + avgWait + "; " + gr8estWait;
            }
            if (i == 480) //480 minutes have passed
            {
                string totalCus = intToStr(totalCustomers);
                string avgWait = intToStr(timeTotal/totalCustomers);
                string gr8estWait = intToStr(greatestWait);
                min480 = " " + totalCus + "; " + avgWait + "; " + gr8estWait;
            }
        }
}//multiple lines to multiple cashiers