Beispiel #1
0
Effect_DescapePreEnd_RightPic::Effect_DescapePreEnd_RightPic(double *ix, double *iy, double get_x_size, double get_y_size) :
	Interface_Effect(ix, iy)
{
	time_by_gene = 0;
	got_graphic_handle = MakeGraph(get_x_size, get_y_size);//グラフィックハンドルの生成
	GetDrawScreenGraph(*ix, *iy, *ix + get_x_size, *iy + get_y_size, got_graphic_handle);
	extend_rate = 1;
	//pre_extend_rate[30] = { 0 };
}
void ReinitializeGraph(graphP *pGraph, int ReuseGraphs, char command)
{
	if (ReuseGraphs)
		gp_ReinitializeGraph(*pGraph);
	else
	{
		graphP newGraph = MakeGraph((*pGraph)->N, command);
		gp_Free(pGraph);
		*pGraph = newGraph;
	}
}
OSStatus CAPlayThrough::SetupGraph(AudioDeviceID out)
{
	OSStatus err = noErr;
	AURenderCallbackStruct output;
	
	//Make a New Graph
    err = NewAUGraph(&mGraph);  
	checkErr(err);

	//Open the Graph, AudioUnits are opened but not initialized    
    err = AUGraphOpen(mGraph);
	checkErr(err);
	
	err = MakeGraph();
	checkErr(err);
		
	err = SetOutputDeviceAsCurrent(out);
	checkErr(err);
	
	//Tell the output unit not to reset timestamps 
	//Otherwise sample rate changes will cause sync los
	UInt32 startAtZero = 0;
	err = AudioUnitSetProperty(mOutputUnit, 
							  kAudioOutputUnitProperty_StartTimestampsAtZero, 
							  kAudioUnitScope_Global,
							  0,
							  &startAtZero, 
							  sizeof(startAtZero));
	checkErr(err);
	
	output.inputProc = OutputProc;
	output.inputProcRefCon = this;
	
	err = AudioUnitSetProperty(mVarispeedUnit, 
							  kAudioUnitProperty_SetRenderCallback, 
							  kAudioUnitScope_Input,
							  0,
							  &output, 
							  sizeof(output));
                              
                        
	checkErr(err);		
	
	return err;
}
Beispiel #4
0
int main() {
  int T;
  scanf("%d", &T);

  for (int t = 0; t < T; ++t) {
    std::vector<std::string> words;
    scanf("%d", &N);

    for (int i = 0; i < N; ++i) {
      char buf[128];
      scanf("%s", buf);
      words.push_back(buf);
    }

    MakeGraph(words);
    std::vector<int> r = TopologicalSort();

    PrintVInt(r);
  }
  //
  return 0;
}
int main (void)
{
    int i, S;
	Graph *G = MakeGraph();

	printf ("Enter the source node index: ");
	scanf ("%d", &S);

	if (S >= G -> NoOfV)
		return 1;
	int Check = BellmanFord (G, G -> V[S]);
    if (Check == 1)
    {
        fprintf (stderr, "\nNegative cycle in the graph!");
        return 0;
    }

	printf ("All data are as follows: \n");
	PrintGraphBFS (G);

	return 0;
}
Beispiel #6
0
int main()
{
	/* Define the Graph */
	int Size;
	Size = GetSize( GRAPH_DATA );

	Graph G;
	G = MakeGraph( Size );

	/* Append Arcs */
	GetArcs(G, GRAPH_DATA);

	/* Print Graph */
	PrintGraph(G);

	/* Topological Sort */
	VertexType *Degree;
	Degree = InDegree(G);

	puts("\nDepth First Topological Sort");
	DfsTopSort(Degree, G);

	return 0;
}
int  RandomGraphs(char command, int NumGraphs, int SizeOfGraphs)
{
char theFileName[256];
int  K, countUpdateFreq;
int Result=OK, MainStatistic=0;
int  ObstructionMinorFreqs[NUM_MINORS];
graphP theGraph=NULL, origGraph=NULL;
platform_time start, end;
int embedFlags = GetEmbedFlags(command);
int ReuseGraphs = TRUE;

     GetNumberIfZero(&NumGraphs, "Enter number of graphs to generate:", 1, 1000000000);
     GetNumberIfZero(&SizeOfGraphs, "Enter size of graphs:", 1, 10000);

   	 theGraph = MakeGraph(SizeOfGraphs, command);
   	 origGraph = MakeGraph(SizeOfGraphs, command);
   	 if (theGraph == NULL || origGraph == NULL)
   	 {
   		 gp_Free(&theGraph);
   		 return NOTOK;
   	 }

     // Initialize a secondary statistics array
     for (K=0; K < NUM_MINORS; K++)
          ObstructionMinorFreqs[K] = 0;

   	 // Seed the random number generator with "now". Do it after any prompting
   	 // to tie randomness to human process of answering the prompt.
   	 srand(time(NULL));

   	 // Select a counter update frequency that updates more frequently with larger graphs
   	 // and which is relatively prime with 10 so that all digits of the count will change
   	 // even though we aren't showing the count value on every iteration
   	 countUpdateFreq = 3579 / SizeOfGraphs;
   	 countUpdateFreq = countUpdateFreq < 1 ? 1 : countUpdateFreq;
   	 countUpdateFreq = countUpdateFreq % 2 == 0 ? countUpdateFreq+1 : countUpdateFreq;
   	 countUpdateFreq = countUpdateFreq % 5 == 0 ? countUpdateFreq+2 : countUpdateFreq;

   	 // Start the count
     fprintf(stdout, "0\r");
     fflush(stdout);

     // Start the timer
     platform_GetTime(start);

     // Generate and process the number of graphs requested
     for (K=0; K < NumGraphs; K++)
     {
          if ((Result = gp_CreateRandomGraph(theGraph)) == OK)
          {
              if (tolower(OrigOut)=='y')
              {
                  sprintf(theFileName, "random\\%d.txt", K%10);
                  gp_Write(theGraph, theFileName, WRITE_ADJLIST);
              }

              gp_CopyGraph(origGraph, theGraph);

              if (strchr("pdo234", command))
              {
                  Result = gp_Embed(theGraph, embedFlags);

                  if (gp_TestEmbedResultIntegrity(theGraph, origGraph, Result) != Result)
                      Result = NOTOK;

                  if (Result == OK)
                  {
                       MainStatistic++;

                       if (tolower(EmbeddableOut) == 'y')
                       {
                           sprintf(theFileName, "embedded\\%d.txt", K%10);
                           gp_Write(theGraph, theFileName, WRITE_ADJMATRIX);
                       }

                       if (tolower(AdjListsForEmbeddingsOut) == 'y')
                       {
                           sprintf(theFileName, "adjlist\\%d.txt", K%10);
                           gp_Write(theGraph, theFileName, WRITE_ADJLIST);
                       }
                  }
                  else if (Result == NONEMBEDDABLE)
                  {
                       if (embedFlags == EMBEDFLAGS_PLANAR || embedFlags == EMBEDFLAGS_OUTERPLANAR)
                       {
                           if (theGraph->IC.minorType & MINORTYPE_A)
                                ObstructionMinorFreqs[0] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_B)
                                ObstructionMinorFreqs[1] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_C)
                                ObstructionMinorFreqs[2] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_D)
                                ObstructionMinorFreqs[3] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_E)
                                ObstructionMinorFreqs[4] ++;

                           if (theGraph->IC.minorType & MINORTYPE_E1)
                                ObstructionMinorFreqs[5] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_E2)
                                ObstructionMinorFreqs[6] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_E3)
                                ObstructionMinorFreqs[7] ++;
                           else if (theGraph->IC.minorType & MINORTYPE_E4)
                                ObstructionMinorFreqs[8] ++;

                           if (tolower(ObstructedOut) == 'y')
                           {
                               sprintf(theFileName, "obstructed\\%d.txt", K%10);
                               gp_Write(theGraph, theFileName, WRITE_ADJMATRIX);
                           }
                       }
                  }
              }
              else if (command == 'c')
              {
      			if ((Result = gp_ColorVertices(theGraph)) == OK)
      				 Result = gp_ColorVerticesIntegrityCheck(theGraph, origGraph);
				if (Result == OK && gp_GetNumColorsUsed(theGraph) <= 5)
					MainStatistic++;
              }

              // If there is an error in processing, then write the file for debugging
              if (Result != OK && Result != NONEMBEDDABLE)
              {
                   sprintf(theFileName, "error\\%d.txt", K%10);
                   gp_Write(origGraph, theFileName, WRITE_ADJLIST);
              }
          }

          // Reinitialize or recreate graphs for next iteration
          ReinitializeGraph(&theGraph, ReuseGraphs, command);
          ReinitializeGraph(&origGraph, ReuseGraphs, command);

          // Show progress, but not so often that it bogs down progress
          if (quietMode == 'n' && (K+1) % countUpdateFreq == 0)
          {
              fprintf(stdout, "%d\r", K+1);
              fflush(stdout);
          }

          // Terminate loop on error
          if (Result != OK && Result != NONEMBEDDABLE)
          {
        	  ErrorMessage("\nError found\n");
              Result = NOTOK;
              break;
          }
     }

     // Stop the timer
     platform_GetTime(end);

     // Finish the count
     fprintf(stdout, "%d\n", NumGraphs);
     fflush(stdout);

     // Free the graph structures created before the loop
     gp_Free(&theGraph);
     gp_Free(&origGraph);

     // Print some demographic results
     if (Result == OK || Result == NONEMBEDDABLE)
         Message("\nNo Errors Found.");
     sprintf(Line, "\nDone (%.3lf seconds).\n", platform_GetDuration(start,end));
     Message(Line);

     // Report statistics for planar or outerplanar embedding
     if (embedFlags == EMBEDFLAGS_PLANAR || embedFlags == EMBEDFLAGS_OUTERPLANAR)
     {
         sprintf(Line, "Num Embedded=%d.\n", MainStatistic);
         Message(Line);

         for (K=0; K<5; K++)
         {
        	  // Outerplanarity does not produces minors C and D
        	  if (embedFlags == EMBEDFLAGS_OUTERPLANAR && (K==2 || K==3))
        		  continue;

              sprintf(Line, "Minor %c = %d\n", K+'A', ObstructionMinorFreqs[K]);
              Message(Line);
         }

         if (!(embedFlags & ~EMBEDFLAGS_PLANAR))
         {
             sprintf(Line, "\nNote: E1 are added to C, E2 are added to A, and E=E3+E4+K5 homeomorphs.\n");
             Message(Line);

             for (K=5; K<NUM_MINORS; K++)
             {
                  sprintf(Line, "Minor E%d = %d\n", K-4, ObstructionMinorFreqs[K]);
                  Message(Line);
             }
         }
     }

     // Report statistics for graph drawing
     else if (embedFlags == EMBEDFLAGS_DRAWPLANAR)
     {
         sprintf(Line, "Num Graphs Embedded and Drawn=%d.\n", MainStatistic);
         Message(Line);
     }

     // Report statistics for subgraph homeomorphism algorithms
     else if (embedFlags == EMBEDFLAGS_SEARCHFORK23)
     {
         sprintf(Line, "Of the generated graphs, %d did not contain a K_{2,3} homeomorph as a subgraph.\n", MainStatistic);
         Message(Line);
     }
     else if (embedFlags == EMBEDFLAGS_SEARCHFORK33)
     {
         sprintf(Line, "Of the generated graphs, %d did not contain a K_{3,3} homeomorph as a subgraph.\n", MainStatistic);
         Message(Line);
     }
     else if (embedFlags == EMBEDFLAGS_SEARCHFORK4)
     {
         sprintf(Line, "Of the generated graphs, %d did not contain a K_4 homeomorph as a subgraph.\n", MainStatistic);
         Message(Line);
     }

     // Report statistics for vertex coloring
     else if (command == 'c')
     {
         sprintf(Line, "Num Graphs colored with 5 or fewer colors=%d.\n", MainStatistic);
         Message(Line);
     }

     FlushConsole(stdout);

     return Result==OK || Result==NONEMBEDDABLE ? OK : NOTOK;
}
int RandomGraph(char command, int extraEdges, int numVertices, char *outfileName, char *outfile2Name)
{
int  Result;
platform_time start, end;
graphP theGraph=NULL, origGraph;
int embedFlags = GetEmbedFlags(command);
char saveEdgeListFormat;

     GetNumberIfZero(&numVertices, "Enter number of vertices:", 1, 1000000);
     if ((theGraph = MakeGraph(numVertices, command)) == NULL)
    	 return NOTOK;

     srand(time(NULL));

     Message("Creating the random graph...\n");
     platform_GetTime(start);
     if (gp_CreateRandomGraphEx(theGraph, 3*numVertices-6+extraEdges) != OK)
     {
         ErrorMessage("gp_CreateRandomGraphEx() failed\n");
         return NOTOK;
     }
     platform_GetTime(end);

     sprintf(Line, "Created random graph with %d edges in %.3lf seconds. ", theGraph->M, platform_GetDuration(start,end));
     Message(Line);
     FlushConsole(stdout);

     // The user may have requested a copy of the random graph before processing
     if (outfile2Name != NULL)
     {
         gp_Write(theGraph, outfile2Name, WRITE_ADJLIST);
     }

     origGraph = gp_DupGraph(theGraph);

     // Do the requested algorithm on the randomly generated graph
     Message("Now processing\n");
     FlushConsole(stdout);

     if (strchr("pdo234", command))
     {
         platform_GetTime(start);
         Result = gp_Embed(theGraph, embedFlags);
         platform_GetTime(end);

    	 gp_SortVertices(theGraph);

         if (gp_TestEmbedResultIntegrity(theGraph, origGraph, Result) != Result)
             Result = NOTOK;
     }
     else if (command == 'c')
     {
         platform_GetTime(start);
    	 Result = gp_ColorVertices(theGraph);
         platform_GetTime(end);
     }
     else
    	 Result = NOTOK;

     // Write what the algorithm determined and how long it took
     WriteAlgorithmResults(theGraph, Result, command, start, end, NULL);

     // On successful algorithm result, write the output file and see if the
     // user wants the edge list formatted file.
     if (Result == OK || Result == NONEMBEDDABLE)
     {
    	 if (outfileName != NULL)
    		 gp_Write(theGraph, outfileName, WRITE_ADJLIST);

         Prompt("Do you want to save the generated graph in edge list format (y/n)? ");
         fflush(stdin);
         scanf(" %c", &saveEdgeListFormat);
         if (tolower(saveEdgeListFormat) == 'y')
         {
        	 char *fileName = "maxPlanarEdgeList.txt";
             if (extraEdges > 0)
            	 fileName = "nonPlanarEdgeList.txt";

             SaveAsciiGraph(theGraph, fileName);
             sprintf(Line, "Edge list format saved to '%s'\n", fileName);
        	 Message(Line);
         }
     }
     else ErrorMessage("Failure occurred");

     gp_Free(&theGraph);
     gp_Free(&origGraph);

     FlushConsole(stdout);
     return Result;
}
Beispiel #9
0
	void solve(void) {
		Input();
		Floyd();
		MakeGraph();
		printf("%lld\n", MinCost());
	}
Beispiel #10
0
	void solve(void) {
		Input();
		MakeGraph();
		printf("%d\n", Sum - Flow());
	}
Beispiel #11
0
void DMplot()
{

    TCanvas *canv = new TCanvas("canv", "limits canvas", 800., 680.);
	gStyle->SetCanvasDefH(600); //Height of canvas
	gStyle->SetCanvasDefW(640); //Width of canvas
	gStyle->SetCanvasDefX(0);   //POsition on screen
	gStyle->SetCanvasDefY(0);

	gStyle->SetPadLeftMargin(0.14);//0.16);
	gStyle->SetPadRightMargin(0.165);//0.02);
	gStyle->SetPadTopMargin(0.085);//0.02);
	gStyle->SetPadBottomMargin(0.12);//0.02);

	  // For g axis titles:
	gStyle->SetTitleColor(1, "XYZ");
	gStyle->SetTitleFont(42, "XYZ");
	gStyle->SetTitleSize(0.045, "Z");
	gStyle->SetTitleSize(0.055, "XY");
	gStyle->SetTitleXOffset(1.0);//0.9);
	gStyle->SetTitleYOffset(1.15); // => 1.15 if exponents

	// For g axis labels:
	gStyle->SetLabelColor(1, "XYZ");
	gStyle->SetLabelFont(42, "XYZ");
	gStyle->SetLabelOffset(0.007, "XYZ");
	gStyle->SetLabelSize(0.04, "XYZ");

	// Legends
	gStyle->SetLegendBorderSize(0);
	gStyle->SetLegendFillColor(kWhite);
	gStyle->SetLegendFont(42);
    TPad* t1d = new TPad();
    t1d = new TPad("t1d","t1d", 0.0, 0.0, 1.0, 1.0);
    t1d->Draw();
    t1d->SetTicky();
    t1d->SetTickx();
    t1d->SetRightMargin(0.03);
    t1d->cd();

    //t1d->SetGridx(1);
    //t1d->SetGridy(1);
    t1d->SetLogy();
    t1d->SetLogx();

    //double const fn = 0.629;//0.326;
    TGraph *h_scalar_min = MakeGraph(0,0.260);
    TGraph *h_scalar_lat = MakeGraph(0,0.326);
    TGraph *h_scalar_max = MakeGraph(0,0.629);
    TGraph *h_fermion_min = MakeGraph(1,0.260);
    TGraph *h_fermion_lat = MakeGraph(1,0.326);
    TGraph *h_fermion_max = MakeGraph(1,0.629);

//////////////////////////////////////////////////

    // Get LUX bound 
    //TGraph *z1 = new TGraph("LUX_90CL.dat","%lg %lg");
    //
    TFile *fi_LUX2015 = TFile::Open("LUX_latest_2015.root");
    TGraph *z12015 =(TGraph*) fi_LUX2015->Get("LUX_2015");
    //TFile *fi_LUX2016 = TFile::Open("LUX_latest_2016.root");
    //TGraph *z12016 =(TGraph*) fi_LUX2016->Get("LUX_2016");
    TFile *fi_LUX2016 = TFile::Open("LUX_2013_2014_2015_combined.root");
    TGraph *z12016 =(TGraph*) fi_LUX2016->Get("LUX_2013_2014_2015_combined");

    z12015->SetLineWidth(3);
    z12015->SetLineColor(kGreen+2);
//    z12015->SetLineStyle(2);
    z12016->SetLineWidth(3);
    //z12016->SetLineStyle(2);
    z12016->SetLineColor(kGreen+2);

//    TLegend *leg2 = new TLegend(0.65, 0.15, 0.93, 0.42);
    TLegend *leg2 = new TLegend(0.70, 0.15, 0.97, 0.42);
    leg2->SetFillColor(0);
    leg2->SetBorderSize(0);
    //leg2->AddEntry(z1,"LUX(90\%CL)","L");
//////////////////////////////////////////////////
//  CDMS/ CRESST TOO
    TFile *CDMS_2016f = TFile::Open("CDMS_2016.root");
    TGraph *SCDMS = (TGraph*)CDMS_2016f->Get("CDMS_2016");

    TFile *CRESST2_2016f = TFile::Open("CRESST_2.root");
    TGraph *CRESST2 = (TGraph*)CRESST2_2016f->Get("CRESST_2_2016");

    TFile *PANDAX_2016f = TFile::Open("PANDAX.root");
    TGraph *PANDAX = (TGraph*)PANDAX_2016f->Get("PANDAX");

    SCDMS->SetLineColor(kAzure+7); SCDMS->SetLineStyle(9); SCDMS->SetLineWidth(3);
    CRESST2->SetLineColor(kMagenta+2); CRESST2->SetLineStyle(7); CRESST2->SetLineWidth(3);
    PANDAX->SetLineColor(kMagenta+2); PANDAX->SetLineStyle(4); PANDAX->SetLineWidth(3);
	
//
//

    h_scalar_min->SetTitle("");
    h_scalar_min->SetMinimum(2.0e-47);
    h_scalar_min->SetMaximum(1.0e-39);
    //h_scalar_min->SetMinimum(0.6e-46);
    //h_scalar_min->SetMaximum(1.0e-42);
    h_scalar_min->SetLineColor(4);
    h_scalar_min->SetLineStyle(2);
    h_scalar_min->SetLineWidth(3);
    h_scalar_min->GetXaxis()->SetTitleOffset(1.03);
    h_scalar_min->GetXaxis()->SetTitle("DM mass [GeV]");
    h_scalar_min->GetYaxis()->SetTitle("DM-nucleon cross section [cm^{2}]");
    h_scalar_lat->SetLineColor(4);
    h_scalar_lat->SetLineStyle(1);
    h_scalar_lat->SetLineWidth(3);
    h_scalar_max->SetLineColor(4);
    h_scalar_max->SetLineStyle(2);
    h_scalar_max->SetLineWidth(3);


    h_fermion_min->SetLineColor(kRed);
    h_fermion_min->SetLineStyle(2);
    h_fermion_min->SetLineWidth(3);
    h_fermion_lat->SetLineColor(kRed);
    h_fermion_lat->SetLineStyle(1);
    h_fermion_lat->SetLineWidth(3);
    h_fermion_max->SetLineColor(kRed);
    h_fermion_max->SetLineStyle(2);
    h_fermion_max->SetLineWidth(3);


    //h_scalar_lat->SetFillStyle(3005);
    //h_scalar_lat->SetLineWidth(-402);

    h_scalar_min->Draw("AL");
    h_scalar_lat->Draw("L");
    h_scalar_max->Draw("L");

    h_fermion_min->Draw("L");
    h_fermion_lat->Draw("L");
    h_fermion_max->Draw("L");
    z12016->Draw("L");
    //z12015->Draw("L");
    //CRESST2->Draw("C");
    SCDMS->Draw("C");
    PANDAX->Draw("C");

    //leg2->Draw();
    TLatex *lat = new TLatex(); lat->SetTextSize(0.025);
    lat->SetTextFont(42);
    lat->SetTextColor(kGreen+2);
    lat->SetTextAngle(15);
    //lat->DrawLatex(130,z1->Eval(130)*1.5,"LUX #it{Phys. Rev. Lett.} #bf{116} (2016)");


    //lat->DrawLatex(130,z12015->Eval(130)*1.5,"LUX (2015)");
    lat->DrawLatex(130,z12016->Eval(130)*0.5,"LUX (2013+2014-16)");
    
    lat->SetTextColor(SCDMS->GetLineColor());
    lat->SetTextAngle(344);
    //lat->SetFillColor(kWhite);
    lat->DrawLatex(5,SCDMS->Eval(5)*1.5,"CDMSlite (2015)");
    
    lat->SetTextColor(kBlue);
    lat->SetTextAngle(330);
    lat->DrawLatex(13,h_scalar_lat->Eval(13)*1.5,"Scalar DM");

    lat->SetTextColor(kRed);
    lat->SetTextAngle(4);
    lat->DrawLatex(5,h_fermion_lat->Eval(5)*1.5,"Fermion DM");


    lat->SetTextColor(kMagenta+2);
    lat->SetTextAngle(15);
    lat->DrawLatex(130,PANDAX->Eval(130)*1.25,"PandaX-II (2016)");

	TLatex * tex = new TLatex();
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetLineWidth(2);
	tex->SetTextSize(0.04);
	tex->SetTextAlign(31);
	tex->DrawLatex(0.93,0.78,"4.9 fb^{-1} (7 TeV) + 19.7 fb^{-1} (8 TeV)");
	tex->DrawLatex(0.93,0.74,"+ 2.3 fb^{-1} (13 TeV)");
	//tex->SetTextAlign(11);
  	tex->SetTextFont(42);
	tex->SetTextSize(0.06);
        TLegend *legBOX; 
	if (isPrelim)	{
   		legBOX = new TLegend(0.16,0.83,0.38,0.89);
		legBOX->SetFillColor(kWhite);
		legBOX->SetLineWidth(0);
		legBOX->Draw();
		tex->DrawLatex(0.17, 0.84, "#bf{CMS} #it{Preliminary}");
	} else {
   		legBOX = new TLegend(0.16,0.83,0.28,0.89);
		legBOX->SetFillColor(kWhite);
		legBOX->SetLineWidth(0);
		//legBOX->Draw();
		tex->DrawLatex(0.93, 0.84, "#bf{CMS}");
	}
  tex->SetTextSize(0.045);
  tex->DrawLatex(0.93,0.68,Form("B(H #rightarrow inv.) < %.2f",BRinv));
  tex->DrawLatex(0.93,0.5,"90% CL limits");
  canv->SetTicky(1);
  canv->SetTickx(1);
  canv->SaveAs("limitsDM.pdf"); 

}
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	//the index of the variables from the left image are 0~numLabels-1 ; right:numLabels~2*numLabels-1
	double *r,*c, *Colors_L, *FLabels_L, *BLabels_L, *FDist_L, *BDist_L,
		          *Colors_R, *FLabels_R, *BLabels_R, *FDist_R, *BDist_R, 
		   *disp , *RelateParam_p , *RelateParam_c ;	
	// Input Arguments

	double *SegImage_L , *SegImage_R ;	// Output Arguments
	int numRows, numCols, numLabels, numFLabels_L, numBLabels_L, numFLabels_R, numBLabels_R ;
	int numCorrs ;
	int i;
	  
	if(nrhs!=15) 
	{
		mexErrMsgTxt("Incorrect No. of inputs");
	} 
	else if(nlhs!=2) 
	{
		mexErrMsgTxt("Incorrect No. of outputs");
	}
	  
	r          = mxGetPr(prhs[0]);
	c          = mxGetPr(prhs[1]);
	Colors_L   = mxGetPr(prhs[2]);
	FLabels_L  = mxGetPr(prhs[3]);
	BLabels_L  = mxGetPr(prhs[4]);	
	FDist_L    = mxGetPr(prhs[5]);
	BDist_L	   = mxGetPr(prhs[6]);	
	Colors_R   = mxGetPr(prhs[7]);
	FLabels_R  = mxGetPr(prhs[8]);
	BLabels_R  = mxGetPr(prhs[9]);	
	FDist_R    = mxGetPr(prhs[10]);
	BDist_R	   = mxGetPr(prhs[11]);	
	disp	   = mxGetPr(prhs[12]);	
	RelateParam_p  = mxGetPr(prhs[13]);  
 	RelateParam_c  = mxGetPr(prhs[14]);     

    double lambda_p = (*RelateParam_p);
    double lambda_c = (*RelateParam_c);
    
	numCols = (int)(*c);		// Image Size
	numRows = (int)(*r);
	numLabels = numRows*numCols;	// Number of labels
	numFLabels_L = mxGetM(prhs[3]);	// Number of ForeGround Labels in l image
	numBLabels_L = mxGetM(prhs[4]);	// Number of BackGround Labels in l image
	numFLabels_R = mxGetM(prhs[8]);	// Number of ForeGround Labels in r image
	numBLabels_R = mxGetM(prhs[9]);	// Number of BackGround Labels in r image

	plhs[0] = mxCreateDoubleMatrix(numRows,numCols, mxREAL);	// Memory Allocated for output SegImage
	plhs[1] = mxCreateDoubleMatrix(numRows,numCols, mxREAL);	// Memory Allocated for output SegImage

	SegImage_L = mxGetPr(plhs[0]);	// variable assigned to the output SegImage
	SegImage_R = mxGetPr(plhs[1]);	// variable assigned to the output SegImage

	printf("Starting MEX Code \n");

	/**** Cast these data structures into correct types 
	and convert into STL Data Structures ****/

	printf("Vectorization 1: colors of pixels \n");
	vector< vector<double> > ColorsVec_L;
	ColorsVec_L.clear();
    for( i=0 ; i<numLabels ; i++ )
	{
		vector<double> tmp;
		tmp.clear();
		tmp.push_back( Colors_L[0*numLabels + i] );
		tmp.push_back( Colors_L[1*numLabels + i] );
		tmp.push_back( Colors_L[2*numLabels + i] );

		ColorsVec_L.push_back(tmp);
	}
	vector< vector<double> > ColorsVec_R;
	ColorsVec_R.clear();
    for( i=0 ; i<numLabels ; i++ )
	{
		vector<double> tmp;
		tmp.clear();
		tmp.push_back( Colors_R[0*numLabels + i] );
		tmp.push_back( Colors_R[1*numLabels + i] );
		tmp.push_back( Colors_R[2*numLabels + i] );

		ColorsVec_R.push_back(tmp);
	}


	printf("Vectorization 2 and 3: distance from foreground and background GMM \n");
	vector<double> FDistVec_L;
	FDistVec_L.clear();
    for(i=0;i<numLabels;i++)
		FDistVec_L.push_back(FDist_L[i]);

	vector<double> BDistVec_L;
	BDistVec_L.clear();
    for(i=0;i<numLabels;i++)
		BDistVec_L.push_back(BDist_L[i]);

	vector<double> FDistVec_R;
	FDistVec_R.clear();
    for(i=0;i<numLabels;i++)
		FDistVec_R.push_back(FDist_R[i]);

	vector<double> BDistVec_R;
	BDistVec_R.clear();
    for(i=0;i<numLabels;i++)
		BDistVec_R.push_back(BDist_R[i]);
	

	printf("Vectorization 4 and 5: no's of superpixels which belong to FG and BG \n");
	vector<int> FGLabelsVec_L;
	FGLabelsVec_L.clear();
	for(i=0;i<numFLabels_L;i++)
		FGLabelsVec_L.push_back((int) FLabels_L[i]);

	vector<int> BGLabelsVec_L;
	BGLabelsVec_L.clear();
	for(i=0;i<numBLabels_L;i++)
		BGLabelsVec_L.push_back((int) BLabels_L[i]);

	vector<int> FGLabelsVec_R;
	FGLabelsVec_R.clear();
	for(i=0;i<numFLabels_R;i++)
		FGLabelsVec_R.push_back((int) FLabels_R[i]);

	vector<int> BGLabelsVec_R;
	BGLabelsVec_R.clear();
	for(i=0;i<numBLabels_R;i++)
		BGLabelsVec_R.push_back((int) BLabels_R[i]);


	printf("Vectorization 6: disparity map \n");
	vector<int> Disparity;
	Disparity.clear();
    for( int c=0 ; c<numCols ; c++ )
        for( int h=0 ; h<numRows ; h++ )
	    {
	    	Disparity.push_back( (int)disp[c*numRows+h] );
	    }


	/**************************************************************/
	/********** Data Structures Converted into Vector Form*********/
	/**************************************************************/


	/**** Actual Image Segmentation Code *********/
	// Adjacency list declaration
	vector< set<int> > neighbors;			

	MakeAdjacencyList( numLabels, numCols, numRows , neighbors );	// Adjacency list made

	printf("Adjacency lists made \n");
	
	//Calculate how many high-order cliques
	int num_high= 0 ;  
	num_high = get_num_corres( Disparity , numRows , numCols ) ;

	Energy<float,float,float> *e = new Energy<float,float,float>( 2*numLabels+4*num_high*5 , (2*numLabels+4*num_high*5)*3 ) ;
	int *vars = new int[2*numLabels+4*num_high*5];   

	MakeGraph( e , vars , neighbors, Disparity ,
		       ColorsVec_L, FGLabelsVec_L, BGLabelsVec_L, FDistVec_L, BDistVec_L,
			   ColorsVec_R, FGLabelsVec_R, BGLabelsVec_R, FDistVec_R, BDistVec_R,
			   numLabels,  num_high , numRows , numCols , lambda_p , lambda_c );
	printf("Graph constructed \n");
	
	SegmentImage( e , vars , numLabels , numRows, numCols,  SegImage_L , SegImage_R );
	printf("Image Segmented \n");
}