コード例 #1
0
bool Ship::checkAxis(Brick* brick, vec3 impulse, vec3 pos, int axis)
{
	float max = maxFlow(brick, m_base, axis);

	if (max > 0 && max < 1.0f)
	{
		std::vector<Brick*> selection;
		std::vector<Joint**> front;

		int selectionTick = g_tick++;
		if (!breakGraph(brick, m_base, max, axis, &selection, &front, selectionTick))
			return false;

		for (int i = 0; i < front.size(); ++i)
		{
			{
				Brick* brick = (*front[i])->connection->brick;
				int numUp = 0;
				int numDown = 0;
				for (int j = 0; j < brick->numConnections; ++j)
				{
					Brick* other = brick->connections[j].other;
					if (other->tick != selectionTick)
					{
						if (other->pos[1] > brick->pos[1])
							numUp++;
						else if (other->pos[1] < brick->pos[1])
							numDown++;
					}
					if (numUp > 0 && numDown > 0)
						return false;
				}
			}

			{
				Brick* brick = (*front[i])->connection->other;
				int numUp = 0;
				int numDown = 0;
				for (int j = 0; j < brick->numConnections; ++j)
				{
					Brick* other = brick->connections[j].other;
					if (other->tick == selectionTick)
					{
						if (other->pos[1] > brick->pos[1])
							numUp++;
						else if (other->pos[1] < brick->pos[1])
							numDown++;
					}
					if (numUp > 0 && numDown > 0)
						return false;
				}
			}
		}


		destroy(brick, &selection, &front, impulse, pos, axis, g_tick++);
		return true;
	}
	return false;
}
コード例 #2
0
int main()
{
  // Create a graph with 6 nodes
  int n=6;
  MatrixGraph<int> G = MatrixGraph<int>(n);
  Node<int>* n1 = new Node<int>(1, 1);
  Node<int>* n2 = new Node<int>(2, 2);
  Node<int>* n3 = new Node<int>(3, 3);
  Node<int>* n4 = new Node<int>(4, 4);
  Node<int>* n5 = new Node<int>(5, 5);
  Node<int>* n6 = new Node<int>(6, 6);
  G.insertNode(n1);
  G.insertNode(n2);
  G.insertNode(n3);
  G.insertNode(n4);
  G.insertNode(n5);
  G.insertNode(n6);

  //Add edges
  G.insertEdge(n1,n2,2);
  G.insertEdge(n1,n3,25);
  G.insertEdge(n2,n4,5);
  G.insertEdge(n2,n3,8);
  G.insertEdge(n2,n5,11);
  G.insertEdge(n3,n4,7);
  G.insertEdge(n3,n5,6);
  G.insertEdge(n4,n6,25);
  G.insertEdge(n5,n6,35);

  // Create an empty flow
  int **f = new int*[G.num_vertex];
  for (int i=0; i<G.num_vertex; i++)
    f[i] = new int[G.num_vertex];

  maxFlow(G,G.id(n1),G.id(n6),f);

  for (int i=0; i<G.num_vertex; i++)
  {
    for (int j=0; j<G.num_vertex; j++)
      cout << f[i][j] << " ";
    cout << endl;
  }

  return 0;
}
コード例 #3
0
ファイル: p544.cpp プロジェクト: ptargino/uvaOnlineJudge
int main() {
	int n, r, indexA, indexB, weight, numCase = 1, i;
	char city[31];
	while (scanf("%d%d", &n, &r) == 2 && n && r) {
		size = 0;
		for (i = 0; i < r; i++) {
			scanf("%s", city);
			indexA = indexOf(city);
			scanf("%s", city);
			indexB = indexOf(city);
			scanf("%d", &weight);
			path[indexA][indexB] = path[indexB][indexA] = weight;
		}
		maxFlow();
		scanf("%s", city);
		indexA = indexOf(city);
		scanf("%s", city);
		indexB = indexOf(city);
		printf("Scenario #%d\n%d tons\n\n", numCase++, path[indexA][indexB]);
	}
}
コード例 #4
0
ファイル: networkFlow.c プロジェクト: rajareddy1863/C-Codes
int main()
{
	int nV, i, max_flow;
	int from, to, weight, check = 1;
	int source, destination;
	printf("Enter the number of vertices: ");
	scanf("%d",&nV);
	
	struct node * graph[nV];
	for(i = 0; i < nV; i++)
	{
		graph[i] = NULL;
	}
	
	printf("Enter in the format __ __ __ (from node, to node, weight)\n");
	printf("Enter '0 0 0' to exit\n");

	while(check != 0)
	{
		scanf("%d",&from);
		scanf("%d",&to);
		scanf("%d",&weight);
		if((from + to + weight) != 0)
		{
		  addEdge(&graph[from], to, weight);
		}
		check = from + to + weight;
	 }
	 
	 printf("Enter source node: ");
	 scanf("%d",&source);
	 
	 printf("Enter destination node: ");
	 scanf("%d",&destination);
	 
	 max_flow = maxFlow(graph, source, destination, nV);
	 printf("Maximum Flow: %d\n",max_flow);
	 return 0;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: 0117prabal/jacobshack
int main(int argc, char *argv[])
{

    int window_DIM = 15;

    std::string fileNameFlow  = "images/groundTruthOF.flo";
    std::string fileNameImg1 = "images/frame1.png";
    std::string fileNameImg2 = "images/frame2.png";

    //////////////////////////////////////////////////////////
    cv::Mat imgRGB1 = cv::imread(fileNameImg1);
    cv::Mat imgRGB2 = cv::imread(fileNameImg2);
    cv::Mat flowGroundTruth;
    float maxFlowGroundTruth;
    read_FLO_file( fileNameFlow, flowGroundTruth, maxFlowGroundTruth );
    //////////////////////////////////////////////////////////
    cv::Mat              imgGRAY1,imgGRAY1_fl;
    cv::Mat              imgGRAY2,imgGRAY2_fl;
    cv::cvtColor(imgRGB1,imgGRAY1,CV_BGR2GRAY);
    cv::cvtColor(imgRGB2,imgGRAY2,CV_BGR2GRAY);
    imgGRAY1.convertTo(imgGRAY1_fl,CV_32FC1);
    imgGRAY2.convertTo(imgGRAY2_fl,CV_32FC1);
    //////////////////////////////////////////////////////////

    cv::Size size = cv::Size(imgGRAY1.cols,imgGRAY1.rows);

    cv::Mat Ix   = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat Iy   = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat IxIx = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat IyIy = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat IxIy = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat It   = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat IxIt = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat IyIt = cv::Mat::zeros( size, CV_32FC1 );
    cv::Mat flow = cv::Mat::zeros( size, CV_32FC2 );

    //////////////////////////////////////////////////////////////////////
    ////  Prepare Derivatives  ///////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////
    cv::Sobel( imgGRAY1, Ix, CV_32FC1, 1, 0, 3, 1, 0, cv::BORDER_DEFAULT);
    cv::Sobel( imgGRAY1, Iy, CV_32FC1, 0, 1, 3, 1, 0, cv::BORDER_DEFAULT);

    cv::multiply(Ix,Ix,IxIx);
    cv::multiply(Iy,Iy,IyIy);
    cv::multiply(Ix,Iy,IxIy);

    It = (imgGRAY2_fl - imgGRAY1_fl);

    cv::multiply(Ix,It,IxIt);
    cv::multiply(Iy,It,IyIt);

    //////////////////////////////////////////////////////////////////////
    ////  Apply Lucas-Kanade  ////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////

    std::cout << "Applying Lucas-Kanade..." << std::endl;
    lucasKanade(IxIx, IyIy, IxIy, IxIt, IyIt, flow, window_DIM);
    std::cout << "Average Angular Error = " << averageAngularError(flow, flowGroundTruth)  << "\n" << std::endl;

    // display result
    cv::Mat flowGroundTruth_RGB = flow_2_RGB( flowGroundTruth, MAX(maxFlowGroundTruth, maxFlow(flow) ) );
    cv::Mat flow_RGB = flow_2_RGB( flow, MAX(maxFlowGroundTruth, maxFlow(flow) ) );

    cv::imshow("lucas_kanade_flow_rgb", flow_RGB);
    cv::imshow("flow_ground_truth_rgb", flowGroundTruth_RGB);

    std::cout << "Press any key to continue... \n" << std::endl;
    cv::waitKey(0);

    //////////////////////////////////////////////////////////////////////
    ////  Apply Horn-Schunck  ////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////

    std::cout << "Applying Horn-Schunck..." << std::endl;
    hornSchunck(IxIx, IyIy, IxIy, IxIt, IyIt, flow);
    std::cout << "Average Angular Error = " << averageAngularError(flow, flowGroundTruth)  << "\n" << std::endl;

    // display result
    flow_RGB = flow_2_RGB( flow, MAX(maxFlowGroundTruth, maxFlow(flow) ) );

    cv::imshow("horn_schunck_flow_rgb", flow_RGB);
    cv::imshow("flow_ground_truth_rgb", flowGroundTruth_RGB);

    std::cout << "Press any key to continue... \n" << std::endl;
    cv::waitKey(0);
}
コード例 #6
0
ファイル: BONUS.c プロジェクト: patbeagan1/AcerArchDev
int main(void) {
//------------------------------------------------	
	char buffer[20];
	char* last;
	FILE* input = fopen("input.txt", "r");
	fgets(buffer, 20, input);
	last = strtok(buffer," \n");
	nodes = atoi(last);
	printf("last = %s, nodes = %i",last, nodes);
 //-----------------------------------------------
	int df[nodes][nodes];
	int edges[nodes];
	int height[nodes];
	int flow[nodes][nodes];
	int capacity[nodes][nodes];
	int ls[nodes];
	int numedges, i, u, v, p, temp, n;
//------------------------------------------------
	while(fgets(buffer, 20, input) != NULL){
		numedges++;
		last = strtok(buffer," \n");
			u=atoi(last);
			printf("%s ", last);
		last = strtok(NULL," \n");
			v=atoi(last);
			printf("%s ", last);
		last = strtok(NULL," \n");
			capacity[u][v] = atoi(last);
			printf("%s ", last);
		printf("\n");
	}
//--------------------------------------------------
	  for (i = 0, p = 0; i < nodes; i++){
		if((i != 0) && (i != nodes-1)) {
		  ls[p] = i;
		  p++;
		}
	  }
//-------------------------------------------------- 
	  height[0] = nodes;
	  edges[0] = 999999999;
	  for (i = 0; i < nodes; i++)
		push(flow, df, capacity, edges, 0, i);
	  p = 0;
	  while (p < nodes - 2) {
		int u = ls[p];
		int old = height[u];
		//discharge(C, F, excess, height, seen, u);
		if (height[u] > old) {
			temp = ls[p];
			for (n = i; n > 0; n--){
				ls[n] = ls[n-1];
			}
			ls[0] = temp;
			p=0;
		}
		else
		  p += 1;
	  }
	  int maxflow = 0;
	  for (i = 0; i < nodes; i++)
		maxflow += flow[0][i];
	 
	  free(ls);
	  free(height);
	  free(edges);
  printf("Capacity:\n");
  //matrix(capacity);
  printf("Max Flow:\n%d\n", maxFlow());
  printf("Flows:\n");
  //matrix(flow);
 
  return 0;
}