Ejemplo n.º 1
0
static OCerror
collect_leaves(OClink link, OCddsnode ddsnode, NClist* leaves)
{
    size_t nsubnodes,i;
    OCerror ocstat = OC_NOERR;
    OCtype octype;
    ocstat = oc_dds_octype(link,ddsnode,&octype);
    if(ocstat != OC_NOERR) goto done;
    if(octype == OC_Atomic) {
        nclistpush(leaves,(void*)ddsnode);
    } else {
        ocstat = oc_dds_nsubnodes(link,ddsnode,&nsubnodes);
        if(ocstat != OC_NOERR) goto done;
        for(i=0;i<nsubnodes;i++) {
	    OCddsnode subnode;
	    ocstat = oc_dds_ithsubnode(link,ddsnode,i,&subnode);
            if(ocstat != OC_NOERR) goto done;
	    ocstat = collect_leaves(link,subnode,leaves);
            if(ocstat != OC_NOERR) goto done;
	}
    }

done:
    return ocstat;
}
Ejemplo n.º 2
0
static void collect_leaves (tsp_bbnode *bbnode, double *lower, int *leafcount,
                            double *leafvals, tsp_bbnode **leafbbs)
{
    if ((bbnode->child0 == (tsp_bbnode *) NULL ||
            bbnode->child1 == (tsp_bbnode *) NULL) &&
            bbnode->lowerbound < *lower) {
        *lower = bbnode->lowerbound;
    }
    if (bbnode->status != BB_DONE) {
        if (leafvals != (double *) NULL) {
            leafvals[*leafcount] = bbnode->lowerbound;
        }
        if (leafbbs != (tsp_bbnode **) NULL) {
            leafbbs[*leafcount] = bbnode;
        }
        (*leafcount)++;
    }
    if (bbnode->child0) {
        collect_leaves (bbnode->child0, lower, leafcount, leafvals, leafbbs);
    }
    if (bbnode->child1) {
        collect_leaves (bbnode->child1, lower, leafcount, leafvals, leafbbs);
    }
}
Ejemplo n.º 3
0
static int report_tree (char *probname, double restart_upbound,
                        int bbcount, double branchzeit, int maxdepth, double mod, char *format,
                        tsp_bbnode *rootbbnode)
{
    double lower = 0.0;
    int leafcount = 0;
    char buf[16384];

    lower = restart_upbound;
    collect_leaves (rootbbnode, &lower, &leafcount, (double *) NULL, (tsp_bbnode **) NULL);

    printf ("%s: >= %.2f <= %.2f bb %d active %d time %.2f\n", probname, lower,
            restart_upbound, bbcount, leafcount, branchzeit);

    output_tree (rootbbnode, buf, 0, 0, maxdepth, mod, format);

    return 0;
}
Ejemplo n.º 4
0
int
dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
{
    unsigned int i,j;
    NCerror ncerr = NC_NOERR;
    OCerror ocstat = OC_NOERR;
    OClink conn = nccomm->oc.conn;
    size_t nsubnodes;
    NClist* dasglobals = nclistnew();
    NClist* dasnodes = nclistnew();
    NClist* dodsextra = nclistnew();
    NClist* varnodes = nclistnew();
    NClist* alldasnodes = nclistnew();

    if(ddsroot == NULL || dasroot == NULL) return NC_NOERR;

    ocstat = collect_alldasnodes(conn,dasroot,alldasnodes);

    /* 1. collect all the relevant DAS nodes;
          namely those that contain at least one
          attribute value.
          Simultaneously look for potential ambiguities
          if found; complain but continue: result are indeterminate.
          also collect globals and DODS_EXTRA separately.
    */
    for(i=0;i<nclistlength(alldasnodes);i++) {
	OCddsnode das = (OCddsnode)nclistget(alldasnodes,i);
	OCtype octype;
        char* ocname = NULL;
	int isglobal = 0;
	int hasattributes = 0;

        OCCHECK(oc_dds_class(conn,das,&octype));
	if(octype == OC_Attribute) continue; /* ignore these for now*/

        OCCHECK(oc_dds_name(conn,das,&ocname));
	OCCHECK(oc_dds_nsubnodes(conn,das,&nsubnodes));

	isglobal = (ocname == NULL ? 0 : isglobalname3(ocname));

	/* catch DODS_EXTRA */
	if(isglobal && ocname != NULL && strcmp(ocname,"DODS_EXTRA")==0) {
	    nclistpush(dodsextra,(void*)das);
	    nullfree(ocname);
	    continue;
	}
	if(ocname == NULL || isglobal) {
            nclistpush(dasglobals,(void*)das);
	    nullfree(ocname);
	    continue;
	}
	hasattributes = hasattribute3(conn,das);
	if(hasattributes) {
	    /* Look for previously collected nodes with same name*/
            for(j=0;j<nclistlength(dasnodes);j++) {
	        OCddsnode das2 = (OCddsnode)nclistget(dasnodes,j);
		char* ocname2;
	        OCCHECK(oc_dds_name(conn,das2,&ocname2));
		if(ocname2 == NULL || ocname == NULL) goto loop;
		if(strcmp(ocname2,"DODS")==0) goto loop;
	        if(strcmp(ocname,ocname2)==0)
		        nclog(NCLOGWARN,"nc_mergedas: potentially ambiguous DAS name: %s",ocname2);
loop:
		nullfree(ocname2);
	    }
	    nclistpush(dasnodes,(void*)das);
	}
	nullfree(ocname);
    }

    /* 2. collect all the leaf DDS nodes (of type NC_Atomic)*/
    ocstat = collect_leaves(link,ddsroot,varnodes);

    /* 3. For each das node, locate matching DDS node(s) and attach
          attributes to the DDS node(s).
          Match means:
          1. DAS->fullname :: DDS->fullname
          2. DAS->name :: DDS->fullname (support DAS names with embedded '.'
          3. DAS->name :: DDS->name
	  4. special case for DODS. Apply 1-3 on DODS parent.
    */
    for(i=0;i<nclistlength(dasnodes);i++) {
	OCddsnode das = (OCddsnode)nclistget(dasnodes,i);
	char* ocfullname = NULL;
	char* ocbasename = NULL;

	if(das == NULL) continue;
	OCCHECK(oc_dds_name(conn,das,&ocbasename));
	if(strcmp(ocbasename,"DODS")==0) {
	    OCddsnode container;
   	    OCCHECK(oc_dds_container(conn,das,&container));
            ASSERT(container != NULL);
	    ocfullname = makeocpathstring3(conn,container,".");
	} else {
	    ocfullname = makeocpathstring3(conn,das,".");
	}
        for(j=0;j<nclistlength(varnodes);j++) {
	    CDFnode* dds = (CDFnode*)nclistget(varnodes,j);
	    char* ddsfullname = makecdfpathstring3(dds,".");
	    if(strcmp(ocfullname,ddsfullname)==0
	       || strcmp(ocbasename,ddsfullname)==0
	       || strcmp(ocbasename,dds->ocname)==0) {
		mergedas1(nccomm,conn,dds,das);
		/* remove from dasnodes list*/
		nclistset(dasnodes,i,(void*)NULL);
	    }
	    nullfree(ddsfullname);
	}
	nullfree(ocfullname);
	nullfree(ocbasename);
    }

    /* 4. Assign globals */
    for(i=0;i<nclistlength(dasglobals);i++) {
	OCddsnode das = (OCddsnode)nclistget(dasglobals,i);
	mergedas1(nccomm,conn,ddsroot,das);
    }

    /* 5. Assign DOD_EXTRA */
    for(i=0;i<nclistlength(dodsextra);i++) {
	OCddsnode das = (OCddsnode)nclistget(dodsextra,i);
	mergedas1(nccomm,conn,ddsroot,das);
    }

done: /* cleanup*/
    nclistfree(dasglobals);
    nclistfree(dasnodes);
    nclistfree(alldasnodes);
    nclistfree(dodsextra);
    nclistfree(varnodes);
    if(ocstat != OC_NOERR)
	ncerr = ocerrtoncerr(ocstat);
    return THROW(ncerr);
}
Ejemplo n.º 5
0
static int report_leaves (char *probname, double restart_upbound,
                          int bbcount, double branchzeit, double mod, char *format,
                          tsp_bbnode *rootbbnode, int shownodes)
{
    double lower = 0.0;
    int leafcount = 0;
    double *leafvals = (double *) NULL;
    tsp_bbnode **leafbbs = (tsp_bbnode **) NULL;
    int *leafperm = (int *) NULL;
    int i;
    int rval = 0;
    char buf[80];
    size_t outcnt;
    double v;

    leafvals = CC_SAFE_MALLOC (bbcount, double);
    if (leafvals == (double *) NULL) {
        fprintf (stderr, "Out of memory in report_leaves\n");
        rval = 1;
        goto CLEANUP;
    }

    if (shownodes) {
        leafbbs = CC_SAFE_MALLOC (bbcount, tsp_bbnode *);
        if (leafbbs == (tsp_bbnode **) NULL) {
            fprintf (stderr, "Out of memory in report_leaves\n");
            rval = 1;
            goto CLEANUP;
        }
    }

    lower = restart_upbound;
    collect_leaves (rootbbnode, &lower, &leafcount, leafvals, leafbbs);

    printf ("%s: >= %.2f <= %.2f bb %d active %d time %.2f\n", probname, lower,
            restart_upbound, bbcount, leafcount, branchzeit);

    if (leafcount == 0) {
        rval = 0;
        goto CLEANUP;
    }

    leafperm = CC_SAFE_MALLOC (leafcount, int);
    if (leafperm == (int *) NULL) {
        fprintf (stderr, "Out of memory in report_leaves\n");
        rval = 1;
        goto CLEANUP;
    }

    for (i=0; i<leafcount; i++) leafperm[i] = i;

    CCutil_double_perm_quicksort (leafperm, leafvals, leafcount);

    outcnt = 0;
    for (i=0; i<leafcount; i++) {
        if (shownodes) {
            show_node (leafbbs[leafperm[i]], mod, format);
        } else {
            v = leafvals[leafperm[i]];
            if (mod > 0.0) v = fmod(v, mod);
            sprintf (buf, format, v);
            outcnt += strlen(buf) + 1;
            if (outcnt >= 75) {
                printf ("\n");
                outcnt = strlen(buf) + 1;
            }
            printf ("%s ",buf);
        }
    }
    if (!shownodes) {
        printf ("\n");
    }
    rval = 0;

CLEANUP:
    CC_IFFREE (leafvals, double);
    CC_IFFREE (leafbbs, tsp_bbnode *);
    CC_IFFREE (leafperm, int);
    return rval;
}