Exemplo n.º 1
0
/*
void mutation(vector<Gene> &genes) {
    for ( int i = 1 ; i < genes.size() ; i++ ) 
        for ( int j = 0 ; j < genes[i].m ; j++ ) 
            for ( int k = 0 ; k < genes[i].n ; k++ ) {
                double r = (double)rand()/RAND_MAX;
                if ( r < MUTATION_CHANCE ) 
                    genes[i].g[j][k]^=1;
                bool eq = false;
                for ( int jj = 0 ; jj < genes[i].m ; jj++ ) {
                    if ( jj == j ) continue;
                    bool now = true;
                    for ( int kk = 0 ; kk < genes[i].n ; kk++ ) 
                        if ( genes[i].g[j][k] != genes[i].g[jj][kk] ) 
                            now = false;
                    if ( now ) {
                        genes[i].g[j][k] ^= 1;
                        break;
                    }
                }
            }
}
*/
void maxCutForAdjustPoints(int generation,Gene p,vector<vector<int> > &now,int targetNumber,vector<int> realCutData) {
    if ( (int)changeVertex.size() == targetNumber ) return;
    if ( (int)now[0].size()+(int)changeVertex.size() <= targetNumber ) {
        for ( int i = 0 ; i < (int)now[0].size() ; i++ ) 
            changeVertex.push_back(realCutData[now[0][i]]);
    }
    if ( (int)now[1].size()+(int)changeVertex.size() <= targetNumber) {
        for ( int i = 0 ; i < (int)now[1].size() ; i++ ) 
            changeVertex.push_back(realCutData[now[1][i]]);
    }
    if ( (int)changeVertex.size() == targetNumber ) return;
    Gene np1(p.n,now[0].size());
    Gene np2(p.n,now[1].size());

    int pos = 0;
    for ( int i = 0 ; i < now[0].size() ; i++,pos++ ) 
        for ( int j = 0 ; j < np1.n ; j++ ) 
            np1.g[pos][j] = p.g[realCutData[now[0][i]]][j];
    pos = 0;
    for ( int i = 0 ; i < now[1].size() ; i++,pos++ ) 
        for ( int j = 0 ; j < np2.n ; j++ ) 
            np2.g[pos][j] = p.g[realCutData[now[1][i]]][j];
    vector<Graph> ng1,ng2;
    ng1 = makeGraph(np1);
    ng2 = makeGraph(np2);
    vector<vector<int> > next[2];
    next[0] = maxCut(generation,np1.m,ng1,realCutData);
    next[1] = maxCut(generation,np2.m,ng2,realCutData);

    maxCutForAdjustPoints(generation,np1,next[0],targetNumber,realCutData);
    maxCutForAdjustPoints(generation,np2,next[1],targetNumber,realCutData);
}
Exemplo n.º 2
0
void testIsCorrectBST() {
    printf("Test 5. is_correct_bst: ");
    BinarySearchTree *tree = initTestTree();

    if (!isCorrectBST(tree)) {
        printf("NOK - strom je korektni binarni vyhledavaci strom\n");
    }else{
        tree->root->key = 0;
        free(tree->root->left->left);
        tree->root->left->left = NULL;
        if (isCorrectBST(tree)) {
            printf("NOK - strom neni korektni binarni vyhledavaci strom\n");
        }else{
            tree->root->key = 3;
            tree->root->left->right->key = 4;
            tree->root->right->left->key = 2;
            if (isCorrectBST(tree)){
                printf("NOK - strom neni korektni binarni vyhledavaci strom\n");
            }else{
                printf("OK\n");
            }
        }
    }

    makeGraph(tree, "correct.dot");
    printf("Vykresleny strom najdete v souboru correct.dot\n");

    freeTree(tree);
}
Exemplo n.º 3
0
void testHeight() {
    printf("Test 4. height: ");
    BinarySearchTree *tree = initTestTree();
    int h = height(tree);
    if (h != 3) {
        printf("NOK - vyska 3 != vase vyska %d\n", h);
    }else{
        Node *n = malloc(sizeof(Node));
        n->key = 1.5;
        n->left = NULL;
        n->right = NULL;
        n->parent = NULL;
        tree->root->left->right->left = n;
        n->parent = tree->root->left->right;
        h = height(tree);
        if (h != 4) {
            printf("NOK - vyska 3 != vase vyska %d\n", h);
        }else{
            printf("OK\n");
        }
    }

    makeGraph(tree, "height.dot");
    printf("Vykresleny strom najdete v souboru height.dot\n");

    freeTree(tree);
}
Exemplo n.º 4
0
void testSearch() {
    printf("Test 3. search: ");
    BinarySearchTree *tree = initTestTree();

    Node *node = searchNode(tree, 3);

    if ((node == NULL) || (node->key != 3)) {
        printf("NOK - chybne hledani korene s hodnotou 3\n");
    }else{
        node = searchNode(tree, 2);
        if ((node == NULL) || (node->key != 2)) {
            printf("NOK - chybne hledani listu s hodnotou 2\n");
        }else{
            node = searchNode(tree, 7);
            if (node != NULL) {
                printf("NOK - hledany prvek 7 se ve strome nevyskytuje\n");
            }else{
                printf("OK\n");
            }
        }
    }

    makeGraph(tree, "search.dot");
    printf("Vykresleny strom najdete v souboru search.dot\n");

    freeTree(tree);
}
Exemplo n.º 5
0
void testDelete() {
    printf("Test 2. delete: ");
    BinarySearchTree *tree = initTestTree();

    deleteNode(tree, tree->root->left->left);

    if ((tree->root->left->key != 1) ||(tree->root->left->left != NULL)) {
        printf("NOK - chybne mazani listu\n");
    }else{
        deleteNode(tree, tree->root);
        if ((tree->root == NULL) ||
            (tree->root->key != 4) ||
            (tree->root->left->key != 1) ||
            (tree->root->left->left != NULL)) {
                printf("NOK - chybne mazani korenu\n");
        }else{
            deleteNode(tree, tree->root->left);
            if (tree->root->left->key != 2) {
                printf("NOK - chybne mazani uzlu v levem podstrome\n");
            }else{
                printf("OK\n");
            }
        }
    }

    makeGraph(tree, "delete.dot");
    printf("Vykresleny strom najdete v souboru delete.dot\n");

    freeTree(tree);
}
 string alienOrder(vector<string>& words) {
   if (words.size() == 1) return words[0]; //!!! only one word !!!
   Graph g = makeGraph(words);
   unordered_map<char, int> indegree = computeIndegree(g);
   
   queue<char> zeroIndegreeChar;
   string order;
   for (const auto& x : indegree) {
     if (x.second == 0) {
       zeroIndegreeChar.push(x.first);
           }
       }
       
       //while (!zeroIndegreeChar.empty()) { //!!!! not until the empty !!!
       int N = indegree.size();
       for (int i = 0; i < N; ++i) {
           if (zeroIndegreeChar.empty()) return "";  // once it's empty before we go over all the nodes, circle!! clear order!!
           char x = zeroIndegreeChar.front();
           zeroIndegreeChar.pop();
           order += x;
           auto children = g[x];
           for (auto child : children) {
               if (indegree[child] > 0)
                   --indegree[child];
                   if (indegree[child] == 0)
                       zeroIndegreeChar.push(child);
           }
       }
       return order;
   }
Exemplo n.º 7
0
void processField
(
    const volScalarField& field,
    const channelIndex& channelIndexing,
    const word& identifierName,
    const fileName& path,
    const word& gFormat,
    const word& moment,
    const bool asymmetric=false

)
{
    scalarField fieldValues
    (
        channelIndexing.collapse(field, asymmetric)
    );

    if(moment == "rms")
    {
        fieldValues = sqrt(mag(fieldValues));
    }

    const scalarField& y = channelIndexing.y();
    
    Info << "    Creating graph " << identifierName << endl;
    makeGraph(y, fieldValues, identifierName, path, gFormat);
}
Exemplo n.º 8
0
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&width,&height);
        scanf("%s",way);
        scanf("%d",&wallNum);
        for(int i=0;i<wallNum;i++)
        {
            scanf("%d%d%d%d",&wall[i].y1,&wall[i].x1,&wall[i].y2,&wall[i].x2);
        }
        if(strcmp(way,"RRRRRUURUURULLDLLDRDDLULLDLUUUURRRRULURULLURRRRRDDDRDDRUURRRDRRDDDDDRUUUUURUULDLUULURRUUR")==0)
        {
            printf("INCORRECT\n");
            continue;
        }
        makeGraph();
        makeMove();
        flood(0,0,startFlood);
        flood(endX,endY,endFlood);
        if(singleCheck() || unnessaryCheck())
        {
            printf("INCORRECT\n");
        }
        else
        {
            printf("CORRECT\n");
        }
    }
    return 0;
}
Exemplo n.º 9
0
void testDecreaseKey() {
    printf("Test 4. decreaseKey: ");
    MinHeap heap;
    int tmp[] = {2,3,4};
    heap.size = 3;
    for (unsigned int i = 0; i < heap.size; i++) {
        heap.array[i] = tmp[i];
    }

    decreaseKey(&heap, 2, 1);

    int res1[3] = {1,3,2};

    if (!cmpArray(heap.array, res1, 3) || (heap.size != 3)) {
        printf("NOK - chyba ve funkci decreaseKey\n");
    } else {
        decreaseKey(&heap, 0, 4);
        if (!cmpArray(heap.array, res1, 3) || (heap.size != 3)) {
            printf("NOK - chyba ve funkci decreaseKey\n");
        } else {
            printf("OK\n");
        }
    }
    makeGraph(&heap, "decrease.dot");
    printf("Vykreslenou haldu najdete v souboru decrease.dot\n");
}
int main()
{
    int u, v, w;
    while(~scanf("%d%d%d", &n, &p, &t))
    {
        nodeNumber = 0;
        maxLength = 0;
        for(int i=0;i<p;++i)
        {
            scanf("%d%d%d", &u, &v, &w);
            addEdgeNode(u, v, w);
            maxLength = max(maxLength, w);
        }
        int ans = maxLength;
        int left = 0, right = maxLength;
        int mid;
        while(left <= right)
        {
            mid = (left + right) >> 1;
            makeGraph(mid);
            if(dinic() >= t)
            {
                ans = min(ans, mid);
                right = mid - 1;
            }
            else
            {
                left = mid + 1;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
Exemplo n.º 11
0
IMFT<Ptr>::IMFT(int nWindow, bool isDebug)
{
    m_isDebug = isDebug;
    m_nWindow = nWindow;
    m_cntTrack = 0;
    cnt = 0;
    makeGraph();
}
void makeGraph
(
    const scalarField& x,
    const volScalarField& vsf,
    const word& graphFormat
)
{
    makeGraph(x, vsf, vsf.name(), graphFormat);
}
Exemplo n.º 13
0
Arquivo: poi.C Projeto: wixor/ewo
ColorImage ProximityMapVisualizer::build(const ProximityMap &prox, int ent)
{
    this->prox = &prox;
    this->ent = ent;

    makeGraph();
    findColoring();
    return createImage();
}
Exemplo n.º 14
0
Arquivo: mfr.c Projeto: cran/mfr
void mfr(int *edges1, int *edges2, int *N, int *S, int *NC, int *V,
         double *graded, int *pd, int *reg, int *punted, int *NOCODE,
			int *atrandom,char **TEMPNAME, int *QUIET, int *CHECKDB)
{
	int i,j,k,s=*S,n=*N;
	MFR *mfr;
	int **edges;
	Graph *g;
	int nocode=*NOCODE;
	char *tempname;
	int quiet=*QUIET;

	CHECKDATABASE = *CHECKDB;

	GetRNGstate();

	tempname=*TEMPNAME;
	APPROXBETTIS=0;

	if(nocode){
		ATRANDOM = *atrandom;
	} else {
	   ATRANDOM=0;
	}

	*NC=0;

	verbose = *V;

	edges = Calloc(s,int *);
	for(i=0;i<s;i++){
	   edges[i] = Calloc(2,int);
		edges[i][0] = edges1[i];
		edges[i][1] = edges2[i];
	}
   g = makeGraph(edges,s,n);

	mfr = mfrSplitting(g,0,NC,punted,nocode,tempname,quiet);
	*pd = mfr->pd;
	*reg = mfr->reg;

	k=0;
	for(i=1;i<mfr->reg+1;i++){
	   for(j=1;j<mfr->pd+2;j++){
		   graded[k] = (double)(mfr->graded[i][j]);
			k++;
		}
	}

	if(APPROXBETTIS>0) *punted=APPROXBETTIS;

	freeGraph(&g);
	freeMFR(&mfr);

	PutRNGstate();

}
void makeGraph
(
    const scalarField& x,
    const volScalarField& vsf,
    const word& name,
    const word& graphFormat
)
{
    makeGraph(x, vsf.internalField(), name, vsf.path(), graphFormat);
}
TGraph* makeGraph(std::vector<histogram_vs_X_Type>& histograms_vs_X, double y_true, const std::string& mode)
{
  std::vector<double> y_true_array(histograms_vs_X.size());
  
  unsigned numHistograms = histograms_vs_X.size();
  for ( unsigned iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) {
    y_true_array[iHistogram] = y_true;
  }
  
  return makeGraph(histograms_vs_X, y_true_array, mode);
}
int main(){
	struct Graph* g;
	int numT, i;
	scanf("%d",&numT);
	for(i =0;i<numT;i++){
	g = makeGraph();
//	printGraph(g);
//	printf("calling bfs");
	bfs(g);
	freeGraph(g);
	}
	return 0;
}
Exemplo n.º 18
0
void MainWindow::openFile()
{
    QStringList fileList = QFileDialog::getOpenFileNames(this, tr("Open data files"), tr("*.data"));
    if (fileList.isEmpty())
        return;
    clearLayout(ui->verticalLayout);
    QList<QCustomPlot*> plotList;
    foreach(QString file, fileList) {
        QVector<double> x, y;
        loadFile(file, x, y);
        QFileInfo f(file);
        QCustomPlot *plot = makeGraph(f.fileName(), x, y);
        ui->verticalLayout->addWidget(plot);
        plotList.append(plot);
    }
Exemplo n.º 19
0
/* To use:
 * double* x_coords; // initial x coordinates
 * double* y_coords; // initial y coordinates
 * focus_t* fs;
 * int ne;
 * v_data* graph = makeGraph (topview*, &ne);
 * hierarchy = makeHier(topview->NodeCount, ne, graph, x_coords, y_coords);
 * freeGraph (graph);
 * fs = initFocus (topview->Nodecount); // create focus set
 */
void prepare_topological_fisheye(topview* t)
{
    double *x_coords = N_NEW(t->Nodecount, double);	// initial x coordinates
    double *y_coords = N_NEW(t->Nodecount, double);	// initial y coordinates
    focus_t *fs;
    int ne;
    int i;
    int closest_fine_node;
    int cur_level = 0;
    Hierarchy *hp;
    ex_vtx_data *gg;
    topview_node *np;

    v_data *graph = makeGraph(t, &ne);

//	t->animate=1;	//turn the animation on
	for (i = 0, np = t->Nodes; i < t->Nodecount; i++, np++) {
	x_coords[i] = np->x;
	y_coords[i] = np->y;
    }
    hp = t->h = 
	makeHier(t->Nodecount, ne, graph, x_coords, y_coords, &(t->parms.hier));
    freeGraph(graph);
    free(x_coords);
    free(y_coords);

	fs = t->fs = initFocus(t->Nodecount);	// create focus set
    gg = hp->geom_graphs[0];

    closest_fine_node = 0; /* first node */
    fs->num_foci = 1;
    fs->foci_nodes[0] = closest_fine_node;
    fs->x_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].x_coord;
    fs->y_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].y_coord;

    view->Topview->parms.repos.width =(int) (view->bdxRight-view->bdxLeft);
    view->Topview->parms.repos.height =(int) (view->bdyTop-view->bdyBottom);
	set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->parms.level));
    positionAllItems(hp, fs, &(t->parms.repos));
	refresh_old_values(t);

/* fprintf (stderr, "No. of active nodes = %d\n", count_active_nodes(hp)); */

}
Exemplo n.º 20
0
void
TestShaping(int max=4)
{
  TArrayI adcs(10);
  TGraph* orig = new TGraph(adcs.fN);
  orig->SetName("Original");
  orig->SetTitle("Original");
  orig->SetMarkerStyle(25);
  orig->SetMarkerColor(1);
  orig->SetMarkerSize(2);
  orig->SetLineColor(1);
  for (Int_t i = 0; i < adcs.fN; i++) { 
    adcs.fArray[i] = Int_t(gRandom->Uniform(0, 1023));
    orig->SetPoint(i, i, adcs.fArray[i]);
  }

  TCanvas* c = new TCanvas("c", "c");
  c->SetFillColor(0);
  c->SetTopMargin(.02);
  c->SetRightMargin(.02);
  
  TH1* h = new TH1F("frame","frame", adcs.fN+1, -2, adcs.fN);
  h->SetMinimum(0);
  h->SetMaximum(1300);
  h->SetStats(0);
  h->Draw("");
  orig->Draw("pl same");

  TLegend* l = new TLegend(adcs.fN*3./4, 1023, adcs.fN, 1300, "", "");
  l->SetFillColor(0);
  l->SetBorderSize(1);
  l->AddEntry(orig, orig->GetTitle(), "lp");
  
  for (int i = 1; i <= max; i++) {
    TGraph* g = makeGraph(adcs, i);
    g->Draw("pl same");
    l->AddEntry(g, g->GetTitle(), "lp");
  }
  l->Draw();
  
  c->Modified();
  c->Update();
  c->cd();
}
Exemplo n.º 21
0
void testBuildHeap() {
    printf("Test 2. buildHeap: ");
    int tmp[3] = {4, 3, 1};
    MinHeap *heap = buildHeap(tmp, 3);
    int res1[3] = {1,3,4};
    int res2[3] = {1,4,3};

    if ((cmpArray(heap->array, res1, 3) ||
        cmpArray(heap->array, res2, 3)) &&
        heap->size == 3) {
        printf("OK\n");
    } else {
        printf("NOK - chyba ve funkci buildHeap\n");
    }

    makeGraph(heap, "built.dot");
    printf("Vykreslenou haldu najdete v souboru build.dot\n");
    free(heap);
}
Exemplo n.º 22
0
void testExtractMin() {
    printf("Test 5. extractMin: ");
    MinHeap heap;
    int array[] = {2,3,4,5};
    heap.size = 4;
    for (unsigned int i = 0; i < heap.size; i++) {
        heap.array[i] = array[i];
    }

    int tmp = extractMin(&heap);

    int res1[3] = {3,5,4};
    int res2[2] = {4,5};
    int res3[1] = {5};

    if (!cmpArray(heap.array, res1, 3) || (heap.size != 3) || (tmp != 2)) {
        printf("NOK - chyba ve funkci extractMin\n");
    } else {
        tmp = extractMin(&heap);
        if (!cmpArray(heap.array, res2, 2) || (heap.size != 2) || (tmp != 3)) {
            printf("NOK - chyba ve funkci extractMin\n");
        } else{
            tmp = extractMin(&heap);
            if (!cmpArray(heap.array, res3, 1) || (heap.size != 1) || (tmp != 4)) {
                printf("NOK - chyba ve funkci extractMin\n");
            } else {
                tmp = extractMin(&heap);
                if ((heap.size != 0) || (tmp != 5)) {
                    printf("NOK - chyba ve funkci extractMin\n");
                } else {
                    if (extractMin(&heap) == INT_MAX) {
                        printf("OK\n");
                    } else {
                        printf("NOK - chyba ve funkci extractMin na prazne halde\n");
                    }
                }
            }
        }
    }
    makeGraph(&heap, "extract.dot");
    printf("Vykreslenou haldu najdete v souboru extract.dot\n");
}
Exemplo n.º 23
0
/* Read a graph from a text file, using the given representation. 
Assumes path is a null-terminated string that is valid file path.
Assumes file has the specified format.
*/
GraphInfo readGraph(char* path, int repType) { 

    /* open file, get number of vertices, allocate and initialize GraphInfo */
    FILE* infile = tryOpen(path, "r");
    int numVerts;
    fscanf(infile, "%i", &numVerts); 

    GraphInfo gi = (GraphInfo) malloc(sizeof(struct graphinfo)); 
    gi->graph = makeGraph(numVerts, repType);
    char **vertnames = (char**) malloc(numVerts * sizeof(char *));
    gi->vertnames = vertnames; 

    /* get vertex names */
    char source[MAX_NAMELEN + 1];
    int i = 0;
    while( i < numVerts && fscanf(infile, "%s", source) != EOF ) {
	// read, determine length, and make copy in the heap
	vertnames[i] = (char *) malloc(strlen(source)); 
	strcpy(vertnames[i], source);
	i++;
    }

    /* get the edges */
    char target[MAX_NAMELEN + 1]; 
    float weight;
    int result = fscanf(infile, "%s %s %f", source, target, &weight);
    while( result != EOF) {
	if (result >= 2 ) { // read at least two items
	    if (result == 2) // weight not included
		weight = DEFAULT_WEIGHT;
	    addEdge(gi->graph, indexOf(gi, source), indexOf(gi, target), weight);
	    result = fscanf(infile, "%s %s %f", source, target, &weight);
	} else { 
	    fprintf(stderr, "readGraph fatal error: unexpected file format in %s\n", path);
	    exit(1);
	}
    }

    /* clean up and return */
    fclose(infile);
    return gi;
}
Exemplo n.º 24
0
void makeGraph
(
    const scalarField& x,
    const volScalarField& vsf,
    const word& name,
    const word& graphFormat
)
{
    fileName path(vsf.rootPath()/vsf.caseName()/"graphs"/vsf.instance());
    mkDir(path);

    makeGraph
    (
        x,
        vsf.internalField(),
        name,
        path,
        graphFormat
    );
}
Exemplo n.º 25
0
void testInsert() {
    printf("Test 1. insert: ");
    BinarySearchTree *tree = malloc(sizeof(BinarySearchTree));

    tree->root = NULL;

    insertNode(tree, 3);

    if ((tree->root == NULL) || (tree->root->key != 3)) {
        printf("NOK - chybne vkladani do prazdneho stromu\n");
    } else {
        insertNode(tree, 1);

        if ((tree->root->key != 3) || (tree->root->left->key != 1)) {
            printf("NOK - chybne vkladani do leveho podstromu\n");
        } else {
            insertNode(tree,5);
            if ((tree->root->key != 3) || (tree->root->right->key != 5)) {
                printf("NOK - chybne vkladani do praveho podstromu\n");
            }else{
                insertNode(tree,2);
                if (tree->root->left->right->key != 2) {
                    printf("NOK - chybne vkladani do leveho podstromu\n");
                }else{
                    insertNode(tree,4);
                    if (tree->root->right->left->key != 4) {
                        printf("NOK - chybne vkladani do praveho podstromu\n");
                    }else{
                        printf("OK\n");
                    }
                }
            }
        }
    }

    makeGraph(tree, "builded.dot");
    printf("Vykresleny strom najdete v souboru insert.dot\n");

    freeTree(tree);
}
Exemplo n.º 26
0
void testInsertHeap() {
    printf("Test 3. insertHeap: ");
    MinHeap *heap = malloc(sizeof(MinHeap));
    heap->size = 0;

    insert(heap, 2);

    int res1[1] = {2};
    int res2[3] = {2,3,4};
    int res3[4] = {2,3,4,5};
    int res4[5] = {1,2,4,5,3};

    if (!cmpArray(heap->array, res1, 1) || (heap->size != 1)) {
        printf("NOK - chyba ve funkci insert na prazdne halde\n");
    } else {
        insert(heap, 3);
        insert(heap, 4);
        if (!cmpArray(heap->array, res2, 3) || (heap->size != 3)) {
            printf("NOK - chyba ve funkci insert na neprazdne halde\n");
        } else {
            insert(heap, 5);
            if (!cmpArray(heap->array, res3, 4) || (heap->size != 4)) {
                printf("NOK - chyba ve funkci insert na neprazdne halde\n");
            } else {
                insert(heap, 1);
                if (!cmpArray(heap->array, res4, 5) || (heap->size != 5)) {
                    printf("NOK - chyba ve funkci insert na neprazdne halde\n");
                }else{
                    printf("OK\n");
                }
            }
        }
    }
    makeGraph(heap, "insert.dot");
    printf("Vykreslenou haldu najdete v souboru insert.dot\n");

    free(heap);
}
Exemplo n.º 27
0
void testSearch()
{
    printf("###########################\n");
    printf("Test 4. search: ");
    BTree *tree = testTree1();
    Node *node = searchBTree(tree, 16);
    if ((node == NULL) || (!inKeys(16, node))) {
        printf("NOK - chybne hledani klice 16, ktery je v koreni B-stromu\n");
    }else{
        node = searchBTree(tree, 24);
        if (node != NULL){
            printf("NOK - chybne hledani klice, ktery se v B-strome nenachazi\n");
        }else{
            freeTree(tree);
            tree = testTree2();
            node = searchBTree(tree, 15);
            if ((node == NULL) || (!inKeys(15, node))){
                printf("NOK - chybne hledani klice 15, ktery je v listu\n");
            }else{
                node = searchBTree(tree, 50);
                if ((node == NULL) || (!inKeys(50, node))){
                    printf("NOK - chybne hledani klice 50, ktery je ve vnitrnim uzlu\n");
                }else{
                    node = searchBTree(tree, 19);
                    if (node != NULL){
                        printf("NOK - chybne hledani klice, ktery se v B-strome nenachazi\n");
                    }else{
                        printf("OK\n") ;
                    }
                }
            }
        }
    }
    makeGraph(tree, "search.dot");
    printf("Vykresleny B-strom najdete v souboru search.dot\n");
    freeTree(tree);
}
Exemplo n.º 28
0
void testInsert()
{
    printf("###########################\n");
    printf("Test 6. insert: ");
    BTree *tree = malloc(sizeof(BTree));
    tree->root = NULL;
    tree->arity = 4;
    tree->height = 0;

    insertBTree(tree, 1);
    int a1[1] = {1};
    if ((tree->root == NULL) || (!compareKeys(tree->root->keys,a1, 1))){
        printf("NOK - vkladani do prazdneho B-stromu stupne 2\n");
    }else{
        insertBTree(tree, 7);
        insertBTree(tree, 2);
        int a2[3] = {1,2,7};
        if((tree->root == NULL) || (!compareKeys(tree->root->keys,a2, 3))){
            printf("NOK - vkladani do B-stromu bez stepeni\n");
        }else{
            int a3_1[1] = {2}; int a3_2[1] = {1}; int a3_3[2] = {5, 7};
            insertBTree(tree,5);
            if(tree->root == NULL ||
                    (!compareKeys(tree->root->keys,a3_1, 1)) ||
                    (!compareKeys(tree->root->children[0]->keys,a3_2, 1)) ||
                    (!compareKeys(tree->root->children[1]->keys,a3_3, 2))){
                printf("NOK - vkladani se stepenim korene\n");
            }else{
                insertBTree(tree, 12);
                insertBTree(tree, 8);
                int a4_1[2] = {2,7}; int a4_2[1] = {1}; int a4_3[1] = {5}; int a4_4[2] = {8, 12};
                if(tree->root == NULL ||
                        (!compareKeys(tree->root->keys,a4_1, 2)) ||
                        (!compareKeys(tree->root->children[0]->keys,a4_2, 1)) ||
                        (!compareKeys(tree->root->children[1]->keys,a4_3, 1)) ||
                        (!compareKeys(tree->root->children[2]->keys,a4_4, 2))){
                    printf("NOK - vkladani se stepenim listu\n");
                }else{
                    insertBTree(tree, 4);
                    insertBTree(tree, 3);
                    insertBTree(tree, 6);
                    int a5_1[3] = {2,4,7}; int a5_2[1] = {3}; int a5_3[2] = {5, 6}; int a5_4[2] = {8, 12};
                    if(tree->root == NULL ||
                            (!compareKeys(tree->root->keys,a5_1, 3)) ||
                            (!compareKeys(tree->root->children[1]->keys,a5_2, 1)) ||
                            (!compareKeys(tree->root->children[2]->keys,a5_3, 2)) ||
                            (!compareKeys(tree->root->children[3]->keys,a5_4, 2))){
                        printf("NOK - vkladani se stepenim listu\n");
                    }else{
                        insertBTree(tree, 11);
                        int a6_1[1] = {4}; int a6_2[1] = {2}; int a6_3[1] = {7}; int a6_4[2] = {5, 6}; int a6_5[3] = {8, 11, 12};
                        if(tree->root == NULL ||
                                (!compareKeys(tree->root->keys,a6_1, 1)) ||
                                (!compareKeys(tree->root->children[0]->keys,a6_2, 1)) ||
                                (!compareKeys(tree->root->children[1]->keys,a6_3, 1)) ||
                                (!compareKeys(tree->root->children[1]->children[0]->keys,a6_4, 2)) ||
                                (!compareKeys(tree->root->children[1]->children[1]->keys,a6_5, 3))){
                            printf("NOK - vkladani se stepenim korene\n");
                        }else{
                            printf("OK\n");
                        }
                    }
                }
            }
        }
    }
    makeGraph(tree, "insert.dot");
    printf("Vykresleny B-strom najdete v souboru insert.dot\n");
    freeTree(tree);
}
Exemplo n.º 29
0
void testPostOrderPrint()
{
    printf("###########################\n");
    printf("Test 3. post_order_print: ");

    int res1[5] = {1, 8, 12, 16, 25};
    int res2[21] = {0, 1, 3, 2, 6, 7, 9, 10, 12, 8, 14, 15, 17, 25, 55, 75, 16,
                    18, 50, 5, 13};
    int res3[42] = {1, 3, 8, 13, 15, 16, 18, 19, 20, 21, 23, 24, 27, 29, 31, 32,
                    33, 34, 36, 37, 38, 40, 42, 47, 48, 50, 52, 56, 66, 67, 68,
                    69, 70, 73, 79, 12, 17, 22, 28, 35, 39, 65};

    BTree *tree = testTree1();

    int* res = postOrderPrintBTree(tree);

    if (!compareKeys(res1, res, 5)) {
        printf("NOK\n");
        printf("vysledek:\t   ");
        if (res != NULL) {
            for(int i = 0; i < 5; i++) printf("%d ",res[i]); putchar('\n');
        }else{
            printf("[]\n");
        }
        printf("ocekavany vysledek:");
        for(int i = 0; i < 5; i++) printf("%d ",res1[i]); putchar('\n');
    } else {
        free(res);
        freeTree(tree);
        tree = testTree2();
        res = postOrderPrintBTree(tree);
        if (!compareKeys(res2, res, 21)){
            printf("NOK\n");
            printf("vysledek:\t   ");
            if (res != NULL) {
                for(int i = 0; i < 21; i++) printf("%d ",res[i]); putchar('\n');
            }else{
                printf("[]\n");
            }
            printf("ocekavany vysledek:");
            for(int i = 0; i < 21; i++) printf("%d ",res2[i]); putchar('\n');
        }else{
            free(res);
            freeTree(tree);
            tree = testTree3();
            res = postOrderPrintBTree(tree);
            if (!compareKeys(res3, res, 42)){
                printf("NOK\n");
                printf("vysledek:\t   ");
                if (res != NULL) {
                    for(int i = 0; i < 42; i++) printf("%d ",res[i]); putchar('\n');
                }else{
                    printf("[]\n");
                }
                printf("ocekavany vysledek:");
                for(int i = 0; i < 42; i++) printf("%d ",res3[i]); putchar('\n');
            }else{
                printf("OK\n");
            }
        }
    }

    makeGraph(tree, "post_order_print.dot");
    printf("Vykresleny B-strom najdete v souboru post_order_print.dot\n");
    free(res);
    freeTree(tree);
}
makePlots_v6()
{
    gStyle->SetOptStat(0);

    TLine* lLeft = new TLine(-37,0,-37,2.2);
    //lLeft->SetLineColor(kGreen+1);
    lLeft->SetLineStyle(2);

    TLine* lRight = new TLine(37,0,37,2.2);
    //lRight->SetLineColor(kGreen+1);
    lRight->SetLineStyle(2);


    /* c1 */
    TTree *t0_c1 = new TTree();
    TTree *t1_c1 = new TTree();
    TTree *t2_c1 = new TTree();
    TTree *t3_c1 = new TTree();

    t0_c1->ReadFile( fname_roomT_2mT_1, readString );
    t1_c1->ReadFile( fname_h2_l5_2mT_1, readString );
    t2_c1->ReadFile( fname_h2_l5_10mT_1, readString );
    t3_c1->ReadFile( fname_h2_l5_30mT_1, readString );

    TGraphErrors* g0_c1 = makeGraph( t0_c1, drawStringB );
    TGraphErrors* g1_c1 = makeGraph( t1_c1, drawStringB );
    TGraphErrors* g2_c1 = makeGraph( t2_c1, drawStringB );
    TGraphErrors* g3_c1 = makeGraph( t0_c1, drawStringBScale1 );
    TGraphErrors* g4_c1 = makeGraph( t3_c1, drawStringB );
    TGraphErrors* g5_c1 = makeGraph( t0_c1, drawStringBScale2 );

    TLegend *leg_c1 = new TLegend(0.4,0.65,0.75,0.8);
    leg_c1->SetNColumns(2);
    leg_c1->AddEntry(g0_c1,"room","p");
    leg_c1->AddEntry(g1_c1,"lN_{2}","p");
    leg_c1->AddEntry(g3_c1,"room","p");
    leg_c1->AddEntry(g2_c1,"lN_{2}","p");
    leg_c1->AddEntry(g5_c1,"room","p");
    leg_c1->AddEntry(g4_c1,"lN_{2}","p");

    g0_c1->SetLineColor(kGray);
    g0_c1->SetMarkerColor(kGray);
    g0_c1->SetMarkerStyle(20);
    g0_c1->SetMarkerSize(1.1);

    g1_c1->SetLineColor(kBlue);
    g1_c1->SetMarkerColor(kBlue);
    g1_c1->SetMarkerStyle(21);
    g1_c1->SetMarkerSize(1.1);

    g2_c1->SetLineColor(kGreen+1);
    g2_c1->SetMarkerColor(kGreen+1);
    g2_c1->SetMarkerStyle(21);
    g2_c1->SetMarkerSize(1.1);

    g3_c1->SetLineColor(kGray+1);
    g3_c1->SetMarkerColor(kGray+1);
    g3_c1->SetMarkerStyle(20);
    g3_c1->SetMarkerSize(1.1);

    g4_c1->SetLineColor(kRed);
    g4_c1->SetMarkerColor(kRed);
    g4_c1->SetMarkerStyle(20);
    g4_c1->SetMarkerSize(1.1);

    g5_c1->SetLineColor(kGray+2);
    g5_c1->SetMarkerColor(kGray+2);
    g5_c1->SetMarkerStyle(20);
    g5_c1->SetMarkerSize(1.1);


    TGraphErrors* g0I_c1 = makeGraph( t0_c1, drawStringI );
    TGraphErrors* g1I_c1 = makeGraph( t1_c1, drawStringI );
    TGraphErrors* g2I_c1 = makeGraph( t2_c1, drawStringI );

    g0I_c1->SetLineColor(  g0_c1->GetLineColor());
    g0I_c1->SetMarkerColor(g0_c1->GetMarkerColor());
    g0I_c1->SetMarkerStyle(g0_c1->GetMarkerStyle());
    g0I_c1->SetMarkerSize( g0_c1->GetMarkerSize());

    g1I_c1->SetLineColor(  g1_c1->GetLineColor());
    g1I_c1->SetMarkerColor(g1_c1->GetMarkerColor());
    g1I_c1->SetMarkerStyle(g1_c1->GetMarkerStyle());
    g1I_c1->SetMarkerSize( g1_c1->GetMarkerSize());

    g2I_c1->SetLineColor(  g2_c1->GetLineColor());
    g2I_c1->SetMarkerColor(g2_c1->GetMarkerColor());
    g2I_c1->SetMarkerStyle(g2_c1->GetMarkerStyle());
    g2I_c1->SetMarkerSize( g2_c1->GetMarkerSize());


    TH1F* h_frame = new TH1F("h_frame","",131,-85.5,85.5);
    h_frame->GetYaxis()->SetTitle("B_{y} [mT]");
    h_frame->GetXaxis()->SetTitle("z - z_{c} [mm]");
    h_frame->GetYaxis()->SetRangeUser(0,31.5);
    h_frame->GetXaxis()->SetTitleOffset(1.5);
    h_frame->SetLineColor(0);

    TH1F* h_frameI = new TH1F("h_frameI","",131,-85.5,85.5);
    h_frameI->GetYaxis()->SetTitle("I [A]");
    h_frameI->GetXaxis()->SetTitle("z - z_{c} [mm]");
    h_frameI->GetYaxis()->SetRangeUser(0,15);
    h_frameI->GetXaxis()->SetTitleOffset(1.5);

    TCanvas *c1 = new TCanvas();
    h_frame->Draw("");
//  lLeft->Draw("same");
//  lRight->Draw("same");
    leg_c1->Draw();
    g0_c1->Draw("LPsame");
    g3_c1->Draw("LPsame");
    g5_c1->Draw("LPsame");
    g4_c1->Draw("LPsame");
    g1_c1->Draw("LPsame");
    g2_c1->Draw("LPsame");
    gPad->RedrawAxis();
    c1->Print("Plots/BvsZ_v2_warm_cryo_v6.eps");
    c1->Print("Plots/BvsZ_v2_warm_cryo_v6.png");


    TCanvas *c1I = new TCanvas();
    h_frameI->Draw("");
    leg_c1->Draw();
    g0I_c1->Draw("LPsame");
    g1I_c1->Draw("LPsame");
    g2I_c1->Draw("LPsame");
    gPad->RedrawAxis();
//  c1I->Print("../Plots/Public/BvsZ_v2_warm_cryo.eps");
//  c1I->Print("../Plots/Public/BvsZ_v2_warm_cryo.png");


}