Example #1
0
void printOrder(Node* node)
{
	if (node != NULL)
	{
		printOrder(node->left);
		printf("%d\n", node->value);
		printOrder(node->right);
	}
}
Example #2
0
void TableListener::onDeleted(const char *rowID, IO2GRow *row)
{
    IO2GOrderRow *order = static_cast<IO2GOrderRow *>(row);
    if (mRequestID == order->getRequestID())
    {
        const char *sStatus = order->getStatus();
        if (sStatus[0] == 'R')
        {
            printOrder("An order has been rejected", order);
        }
        else
        {
            printOrder("An order is going to be removed", order);
        }
        mResponseListener->stopWaiting();
    }
}
Example #3
0
/*
 * Method to process staff menu
 *
 * Daniel Lennart
 */
void handleProcessMenu (int opt) {
    switch (opt) {
    case 1: {
        int i;
        for (i=0;i<queue_index;i++) {
            printOrder(productQueue[i]);
        }
        break;
    } case 2: {
        Order order = getFromQueue();
        printOrder(order);
        break;
    } case 3: {
        printf("There are %d orders.\n", queue_index);
        break;
    } case 4: {
        break;
    } default: {
        printf("Incorrect Option");
        handleProcessMenu(opt);
        break;
    }
    }
}
Example #4
0
void print(Tree* tree)
{
	int choice;

	do
	{

		system("cls");
		printf("1. Print preorder\n");
		printf("2. Print postorder\n");
		printf("3. Print inorder\n");
		printf("9. Back\n");
		scanf("%d", &choice);

		switch (choice)
		{
		case 1:
			system("cls");
			printf("Printing preorder...\n\n");
			printPre(tree->root);
			printf("\n");
			system("pause");
			break;
		case 2:
			system("cls");
			printf("Printing postorder...\n\n");
			printPost(tree->root);
			printf("\n");
			system("pause");
			break;
		case 3:
			system("cls");
			printf("Printing inorder...\n\n");
			printOrder(tree->root);
			printf("\n");
			system("pause");
			break;
		case 9:
			break;
		default:
			printf("Your choice was out of range!\n");
			system("pause");
			break;
		}
	} while ((choice > 3 || choice < 1) && choice != 9);

}
Example #5
0
ostream& operator<< (ostream& o, WikiGraph const& g) {
    if (g.get_num_nodes() == 0) return o ; //nothing to print
    
    // we will have to order all indeces from 1 to lst.size()
    vector<WikiGraph::WikiPage> printOrder(g.node_to_wiki.size()-1);
    for (int i=0; i < printOrder.size(); i++) {
        printOrder[i] = g.node_to_wiki[i+1];
    }
    sort(printOrder.begin(), printOrder.end(), sortByArticleName);
    
    //visit the adjacency lists in the order that was determined by the sort function
    for(auto& wp : printOrder) {
        cout << "Page \"" << wp.title << "\" -> ";
        auto lst = g.get_adj_list();
        for (auto& e : lst[wp.ID]) {
            cout << g.node_to_wiki[e.destination].title << ":" << e.weight << ", ";
        }
        cout << endl;
    }
    return o;
}
void CPLPSolver::Solve(float& resX, float& resY)
{
	printArray(constraints);

	usedSafest = false;

	filter.clear();
	createRandomOrder();

	float tx = 0.f;
	float ty = 0.f;
	float tx2 = 0.f;
	float ty2 = 0.f;

	resX = u;
	resY = v;

	printOrder(order);

	if (debug)
	{
		UE_LOG(LogRVOTest, Warning, TEXT("u v : %f %f  "), u, v);

		UE_LOG(LogRVOTest, Warning, TEXT("All constraints: "));

		for (int i = 0; i < constraints.size() / 3; i++)
		{
			int id = order[i];
			int pos = id * 3;
			if (constraintTypes[id] == CT_LINEAR)
			{
				UE_LOG(LogRVOTest, Warning, TEXT("%d lin: %f %f %f "), id, constraints[pos], constraints[pos + 1], constraints[pos + 2]);
			}
			else
			{
				UE_LOG(LogRVOTest, Warning, TEXT("%d cir: %f %f %f "), id, constraints[pos], constraints[pos + 1], constraints[pos + 2]);
			}
			
		}
	}
	
	

	for (int i = 0; i < constraints.size() / 3; i++)
	{
		if (pointSatisfiesConstraint(resX, resY, order[i]))
		{
			continue;
		}
		int id = order[i];
		int pos = id * 3;

		
		

		bool first = false;
		if (constraintTypes[id] == CT_LINEAR)
		{
			BMU::OrthogonalProjectionOfPointOnLine(constraints[pos], constraints[pos + 1], constraints[pos + 2], u, v, tx, ty);
			first = true;
		}
		else
		{
			first = BMU::OrthogonalProjectionOfPointOnCircle(constraints[pos], constraints[pos + 1], constraints[pos + 2], u, v, tx, ty);
			if (!first)
			{
				UE_LOG(LogRVOTest, Warning, TEXT("%d. constr : %f %f %f  "), id, constraints[pos], constraints[pos + 1], constraints[pos + 2]);
			}
		}
		
		filter.clear();
		filter.insert(id);

		feasible = false;
		float minDistSqr = -1.f;
		float tdist;
		
		if (first && pointSatisfiesConstraints(tx, ty, i))
		{
			feasible = true;
			tdist = (tx - u) * (tx - u) + (ty - v) * (ty - v);
			minDistSqr = tdist;
			resX = tx;
			resY = ty;
			if (BMU::isnanf(resX) || BMU::isnanf(resY))
			{
				UE_LOG(LogRVOTest, Warning, TEXT("cplpsolver::solve  %f %f %f %f %f %f %f"), constraints[pos], constraints[pos + 1], constraints[pos + 2], u, v, tx, ty);
			}
		}
		


		for (int j = 0; j < i; j++)
		{
			int jd = order[j];
			int pos2 = jd * 3;

			filter.clear();
			filter.insert(id);
			filter.insert(jd);

			bool onePoint = false;
			bool hasIntersection = false;
			if (constraintTypes[id] == CT_LINEAR && constraintTypes[jd] == CT_LINEAR)
			{
				hasIntersection = BMU::IntersectLines(constraints[pos], constraints[pos + 1], constraints[pos + 2], constraints[pos2], constraints[pos2 + 1], constraints[pos2 + 2], tx, ty);
				onePoint = true;
			}
			else if (constraintTypes[id] == CT_LINEAR && constraintTypes[jd] == CT_CIRCLE)
			{
				hasIntersection = BMU::IntersectLineCircle(constraints[pos], constraints[pos + 1], constraints[pos + 2], constraints[pos2], constraints[pos2 + 1], constraints[pos2 + 2], tx, ty, tx2, ty2);
			}
			else if (constraintTypes[id] == CT_CIRCLE && constraintTypes[jd] == CT_LINEAR)
			{
				hasIntersection = BMU::IntersectLineCircle(constraints[pos2], constraints[pos2 + 1], constraints[pos2 + 2], constraints[pos], constraints[pos + 1], constraints[pos + 2], tx, ty, tx2, ty2);
			}
			else if (constraintTypes[id] == CT_CIRCLE && constraintTypes[jd] == CT_CIRCLE)
			{
				
				hasIntersection = BMU::IntersectCircleCircle(constraints[pos], constraints[pos + 1], constraints[pos + 2], constraints[pos2], constraints[pos2 + 1], constraints[pos2 + 2], tx, ty, tx2, ty2);
				if (!hasIntersection)
				{
					float U1, V1, R1, U2, V2, R2;
					U1 = constraints[pos]; V1 = constraints[pos + 1]; R1 = constraints[pos + 2]; U2 = constraints[pos2]; V2 = constraints[pos2 + 1]; R2 = constraints[pos2 + 2];

					UE_LOG(LogRVOTest, Warning, TEXT("cir cir: %f %f %f %f %f %f"), U1, V1, R1, U2, V2, R2);

					BMU::debug = true;
					BMU::IntersectCircleCircle(U1, V1, R1, U2, V2, R2, tx, ty, tx2, ty2);
					BMU::debug = false;

					Reset();
					if (pos > pos2)
					{
						AddConstraintCircle(U2, V2, R2);
						AddConstraintCircle(U1, V1, R1);
					}
					else
					{
						AddConstraintCircle(U1, V1, R1);
						AddConstraintCircle(U2, V2, R2);
					}
					
					feasible = false;
					return;
				}
				
			}
			if (hasIntersection)
			{
				if (pointSatisfiesConstraints(tx, ty, i))
				{
					tdist = (tx - u) * (tx - u) + (ty - v) * (ty - v);
					if (!feasible || tdist < minDistSqr)
					{
						feasible = true;
						resX = tx;
						resY = ty;
						minDistSqr = tdist;
						if (BMU::isnanf(resX) || BMU::isnanf(resY))
						{
							if (constraintTypes[id] == CT_LINEAR)
							{
								UE_LOG(LogRVOTest, Warning, TEXT("lin: "));
							}
							else
							{
								UE_LOG(LogRVOTest, Warning, TEXT("cir: "));
							}
								
							UE_LOG(LogRVOTest, Warning, TEXT("%f %f %f "), constraints[pos], constraints[pos + 1], constraints[pos + 2]);
						}
					}
				}

				if (!onePoint && pointSatisfiesConstraints(tx2, ty2, i))
				{
					tdist = (tx2 - u) * (tx2 - u) + (ty2 - v) * (ty2 - v);
					if (!feasible || tdist < minDistSqr)
					{
						feasible = true;
						resX = tx2;
						resY = ty2;
						minDistSqr = tdist;
						if (BMU::isnanf(resX) || BMU::isnanf(resY))
						{
							if (constraintTypes[jd] == CT_LINEAR)
							{
								UE_LOG(LogRVOTest, Warning, TEXT("lin: "));
							}
							else
							{
								UE_LOG(LogRVOTest, Warning, TEXT("cir: "));
							}
							UE_LOG(LogRVOTest, Warning, TEXT("%f %f %f "), constraints[pos2], constraints[pos2 + 1], constraints[pos2 + 2]);
						}
					}
				}
			}
		}
		if (!feasible)
		{
			SolveSafest(i, resX, resY);
			feasible = true;
			return;
		}
	}

	//TODO optimizing current solution : currently runtime should be O(n^2) where n is number of constraints,
	// but the average runtime should be O(n) if implementation is the same as in [De Berg et al. 2008]
}
Example #7
0
void consumer(void *arg)
{
	char *myCategory;
	myCategory = (char *)arg; // the category used to identify which orders should be taken out of the buffer
	int allRetrieved; // flag indicates that this consumer has removed all entries of its category
	allRetrieved = 0; // 0 means the all orders have not been retrieved, 1 means that they have.	

	Order *toProcess[MAX];
	int i;
	for(i = 0; i < MAX; i++) // initializes the local array of orders to be processed.
		toProcess[i] = NULL;


	int processCount; // indexes the toProcess array
	processCount = 0;
	while(ordersLeft != 0)
	{
		printf("Acquiring the mutex...\n");	
		pthread_mutex_lock(&mutex);
		int check;
		check = 0;
	
		while((count == 0) || (allRetrieved == 1))
		{
		
			/*
			if(done == 1)
			{
				printf("About to exit the consumer with category %s\n",myCategory);
				pthread_exit(0);
			}
			*/
			if(ordersLeft == 0)
			{
				pthread_mutex_lock(&dummy);
				printf("Waiting on the dummy\n",myCategory);
				pthread_cond_wait(&exitVar,&dummy);
				printf("Exiting the %s thread...\n",myCategory);
				pthread_exit(0);
			}


			printf("%s thread about to wait...\n",myCategory);
			pthread_cond_signal(&spaceAvailable);
			pthread_cond_wait(&dataAvailable,&mutex);
			allRetrieved = 0;

		}

		printf("\nConsumer: Retrieving orders\n");

		Order *myOrder;

		int x;
		for(x = 0; (x < MAX) && (isSampleNull() == 0); x++)
		{
			if(sample[x] != NULL)
			{	
				check = strcmp(sample[x]->category,myCategory);
	
				if(check == 0)
				{
	
					myOrder = sample[x];
					toProcess[processCount] = sample[x];
				
					sample[x] = NULL;
					processCount++;
					--count;
				}
			}	
		}
		allRetrieved = 1;
		printf("Giving up the mutex...\n");
		pthread_mutex_unlock(&mutex);
		printf("Let's see what we have in the consumer...\n");
		for(x = 0; x < MAX; x++)
		{
			if(toProcess[x] != NULL)
			{
				printOrder(toProcess[x]);
				printf("\n");
				toProcess[x] = NULL;
			}
		}

	//sleep(3);	


	}

	printf("Consumer exiting...\n");
//	pthread_exit(0);
}