コード例 #1
0
ファイル: cplex_solver.c プロジェクト: aeolus-project/opossum
// solution initialisation
int cplex_solver::init_solutions() {
	int status;
	int cur_numcols = CPXgetnumcols (env, lp);

	if (solution != (double *)NULL) free(solution);

	if ((solution = (double *)malloc(nb_vars*sizeof(double))) == (double *)NULL) {
		fprintf (stderr, "cplex_solver: init_solutions: cannot get enough memory to store solutions.\n");
		exit(-1);
	}

	status = CPXgetx (env, lp, solution, 0, cur_numcols-1);
	if ( status ) {
		fprintf (stderr, "cplex_solver: init_solutions: failed to get solutions.\n");
		exit(-1);
	} else if (verbosity >= VERBOSE) {
		// Output model to file (when requested)
		writesol(C_STR("sol-cplex.xml"));
	}
	return 0;
}
コード例 #2
0
ファイル: rtksvr.c プロジェクト: cyborg-x1/rtk_debug
static void *rtksvrthread(void *arg)
#endif
{
    rtksvr_t *svr=(rtksvr_t *)arg;
    obs_t obs;
    obsd_t data[MAXOBS*2];
    double tt;
    unsigned int tick,ticknmea;
    unsigned char *p,*q;
    int i,j,n,fobs[3],cycle,cputime;
    INIT_ZERO(fobs);

    
    tracet(3,"rtksvrthread:\n");
    
    svr->state=1; obs.data=data;
    svr->tick=tickget();
    ticknmea=svr->tick-1000;
    
    for (cycle=0;svr->state;cycle++) {
        tick=tickget();
        
        for (i=0;i<3;i++) {
            p=svr->buff[i]+svr->nb[i]; q=svr->buff[i]+svr->buffsize;
            
            /* read receiver raw/rtcm data from input stream */
            if ((n=strread(svr->stream+i,p,q-p))<=0) {
                continue;
            }
            /* write receiver raw/rtcm data to log stream */
            strwrite(svr->stream+i+5,p,n);
            svr->nb[i]+=n;
            
            /* save peek buffer */
            rtksvrlock(svr);
            n=n<svr->buffsize-svr->npb[i]?n:svr->buffsize-svr->npb[i];
            memcpy(svr->pbuf[i]+svr->npb[i],p,n);
            svr->npb[i]+=n;
            rtksvrunlock(svr);
        }
        for (i=0;i<3;i++) {
            if (svr->format[i]==STRFMT_SP3||svr->format[i]==STRFMT_RNXCLK) {
                /* decode download file */
                decodefile(svr,i);
            }
            else {
                /* decode receiver raw/rtcm data */
                fobs[i]=decoderaw(svr,i);
            }
        }
        for (i=0;i<fobs[0];i++) { /* for each rover observation data */
            obs.n=0;
            for (j=0;j<svr->obs[0][i].n&&obs.n<MAXOBS*2;j++) {
                obs.data[obs.n++]=svr->obs[0][i].data[j];
            }
            for (j=0;j<svr->obs[1][0].n&&obs.n<MAXOBS*2;j++) {
                obs.data[obs.n++]=svr->obs[1][0].data[j];
            }
            /* rtk positioning */
            rtksvrlock(svr);
            rtkpos(&svr->rtk,obs.data,obs.n,&svr->nav);
            rtksvrunlock(svr);
            
            if (svr->rtk.sol.stat!=SOLQ_NONE) {
                
                /* adjust current time */
                tt=(int)(tickget()-tick)/1000.0+DTTOL;
                timeset(gpst2utc(timeadd(svr->rtk.sol.time,tt)));
                
                /* write solution */
                writesol(svr,i);
            }
            /* if cpu overload, inclement obs outage counter and break */
            if ((int)(tickget()-tick)>=svr->cycle) {
                svr->prcout+=fobs[0]-i-1;
#if 0 /* omitted v.2.4.1 */
                break;
#endif
            }
        }
        /* send null solution if no solution (1hz) */
        if (svr->rtk.sol.stat==SOLQ_NONE&&cycle%(1000/svr->cycle)==0) {
            writesol(svr,0);
        }
        /* send nmea request to base/nrtk input stream */
        if (svr->nmeacycle>0&&(int)(tick-ticknmea)>=svr->nmeacycle) {
            if (svr->stream[1].state==1) {
                if (svr->nmeareq==1) {
                    strsendnmea(svr->stream+1,svr->nmeapos);
                }
                else if (svr->nmeareq==2&&norm(svr->rtk.sol.rr,3)>0.0) {
                    strsendnmea(svr->stream+1,svr->rtk.sol.rr);
                }
            }
            ticknmea=tick;
        }
        if ((cputime=(int)(tickget()-tick))>0) svr->cputime=cputime;
        
        /* sleep until next cycle */
        sleepms(svr->cycle-cputime);
    }
    for (i=0;i<MAXSTRRTK;i++) strclose(svr->stream+i);
    for (i=0;i<3;i++) {
        svr->nb[i]=svr->npb[i]=0;
        free(svr->buff[i]); svr->buff[i]=NULL;
        free(svr->pbuf[i]); svr->pbuf[i]=NULL;
        free_raw (svr->raw +i);
        free_rtcm(svr->rtcm+i);
    }
    for (i=0;i<2;i++) {
        svr->nsb[i]=0;
        free(svr->sbuf[i]); svr->sbuf[i]=NULL;
    }
    return 0;
}