int
get_nearest_monitor_rect( int  *x, int *y, int  *width, int  *height )
{
    SDL_SysWMinfo info;
    Display*      display;
    int           screen;

    SDL_VERSION(&info.version);

    if ( !SDL_GetWMInfo(&info) ) {
        D( "%s: SDL_GetWMInfo() failed: %s", __FUNCTION__, SDL_GetError());
        return -1;
    }

    if (x11_lib_init() < 0)
        return -1;

    display = info.info.x11.display;
    screen  = FF(XDefaultScreen)(display);

    *x      = 0;
    *y      = 0;
    *width  = FF(XDisplayWidth)(display, screen);
    *height = FF(XDisplayHeight)(display, screen);

    D("%s: found (x,y,w,h)=(%d,%d,%d,%d)", __FUNCTION__,
      *x, *y, *width, *height);

    return 0;
}
Exemplo n.º 2
0
/* common */
static void *qpa_audio_init (void)
{
    void*  result = NULL;

    D("%s: entering", __FUNCTION__);
    pa_lib = dlopen( "libpulse-simple.so", RTLD_NOW );
    if (pa_lib == NULL)
        pa_lib = dlopen( "libpulse-simple.so.0", RTLD_NOW );

    if (pa_lib == NULL) {
        D("could not find libpulse on this system\n");
        goto Exit;
    }

    if (pa_dynlink_init(pa_lib) < 0)
        goto Fail;

    {
        pa_sample_spec  ss;
        int             error;
        pa_simple*      simple;

        ss.format   = PA_SAMPLE_U8;
        ss.rate     = 44100;
        ss.channels = 1;

        /* try to open it for playback */
        simple = FF(pa_simple_new) (
            conf.server,
            "qemu",
            PA_STREAM_PLAYBACK,
            conf.sink,
            "pcm.playback",
            &ss,
            NULL,                   /* channel map */
            NULL,                   /* buffering attributes */
            &error
            );

        if (simple == NULL) {
            D("%s: error opening open pulse audio library: %s",
              __FUNCTION__, FF(pa_strerror)(error));
            goto Fail;
        }
        FF(pa_simple_free)(simple);
    }

    result = &conf;
    goto Exit;

Fail:
    D("%s: failed to open library\n", __FUNCTION__);
    dlclose(pa_lib);

Exit:
    D("%s: exiting", __FUNCTION__);
    return result;
}
Exemplo n.º 3
0
	void configure_filtergraph(
		AVFilterGraph& graph, 
		const std::string& filtergraph, 
		AVFilterContext& source_ctx, 
		AVFilterContext& sink_ctx)
	{
		AVFilterInOut* outputs = nullptr;
		AVFilterInOut* inputs = nullptr;

		try
		{
			if(!filtergraph.empty()) 
			{
				outputs = avfilter_inout_alloc();
				inputs  = avfilter_inout_alloc();

				CASPAR_VERIFY(outputs && inputs);

				outputs->name       = av_strdup("in");
				outputs->filter_ctx = &source_ctx;
				outputs->pad_idx    = 0;
				outputs->next       = nullptr;

				inputs->name        = av_strdup("out");
				inputs->filter_ctx  = &sink_ctx;
				inputs->pad_idx     = 0;
				inputs->next        = nullptr;

				FF(avfilter_graph_parse(
					&graph, 
					filtergraph.c_str(), 
					inputs,
					outputs,
					nullptr));
			} 
			else 
			{
				FF(avfilter_link(
					&source_ctx, 
					0, 
					&sink_ctx, 
					0));
			}

			FF(avfilter_graph_config(
				&graph, 
				nullptr));
		}
		catch(...)
		{
			avfilter_inout_free(&outputs);
			avfilter_inout_free(&inputs);
			throw;
		}
	}
Exemplo n.º 4
0
static int qpa_init_in (HWVoiceIn *hw, struct audsettings *as)
{
    int error;
    static pa_sample_spec ss;
    struct audsettings obt_as = *as;
    PAVoiceIn *pa = (PAVoiceIn *) hw;

    ss.format = audfmt_to_pa (as->fmt, as->endianness);
    ss.channels = as->nchannels;
    ss.rate = as->freq;

    obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);

    pa->s = FF(pa_simple_new) (
        conf.server,
        "qemu",
        PA_STREAM_RECORD,
        conf.source,
        "pcm.capture",
        &ss,
        NULL,                   /* channel map */
        NULL,                   /* buffering attributes */
        &error
        );
    if (!pa->s) {
        qpa_logerr (error, "pa_simple_new for capture failed\n");
        goto fail1;
    }

    audio_pcm_init_info (&hw->info, &obt_as);
    hw->samples = conf.samples;
    pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
    if (!pa->pcm_buf) {
        dolog ("Could not allocate buffer (%d bytes)\n",
               hw->samples << hw->info.shift);
        goto fail2;
    }

    if (audio_pt_init (&pa->pt, qpa_thread_in, hw, AUDIO_CAP, AUDIO_FUNC)) {
        goto fail3;
    }

    return 0;

 fail3:
    qemu_free (pa->pcm_buf);
    pa->pcm_buf = NULL;
 fail2:
    FF(pa_simple_free) (pa->s);
    pa->s = NULL;
 fail1:
    return -1;
}
Exemplo n.º 5
0
void		re_init_frac(t_mlx *f)
{
	FF(coef) = 0.78;
	FF(zoom) = 0;
	FF(r) = 5;
	FF(g) = 10;
	FF(b) = 5;
	if (ft_strcmp(f->name, "Mandelbrot") == 0)
		ini_mandelbrot(f);
	else if (ft_strcmp(f->name, "Julia") == 0)
		ini_julia(f);
	else if (ft_strcmp(f->name, "Burning-Ship") == 0)
		ini_burning(f);
}
int
get_monitor_resolution( int  *px_dpi, int  *py_dpi )
{
    SDL_SysWMinfo info;
    Display*      display;
    int           screen;
    int           width, width_mm, height, height_mm, xdpi, ydpi;

    SDL_VERSION(&info.version);

    if ( !SDL_GetWMInfo(&info) ) {
        D( "%s: SDL_GetWMInfo() failed: %s", __FUNCTION__, SDL_GetError());
        return -1;
    }

    if (x11_lib_init() < 0)
        return -1;

    display = info.info.x11.display;
    screen  = FF(XDefaultScreen)(display);

    width     = FF(XDisplayWidth)(display, screen);
    width_mm  = FF(XDisplayWidthMM)(display, screen);
    height    = FF(XDisplayHeight)(display, screen);
    height_mm = FF(XDisplayHeightMM)(display, screen);

    if (width_mm <= 0 || height_mm <= 0) {
        D( "%s: bad screen dimensions: width_mm = %d, height_mm = %d",
                __FUNCTION__, width_mm, height_mm);
        return -1;
    }

    D( "%s: found screen width=%d height=%d width_mm=%d height_mm=%d",
            __FUNCTION__, width, height, width_mm, height_mm );

    xdpi = width  * MM_PER_INCH / width_mm;
    ydpi = height * MM_PER_INCH / height_mm;

    if (xdpi < 20 || xdpi > 400 || ydpi < 20 || ydpi > 400) {
        D( "%s: bad resolution: xpi=%d ydpi=%d", __FUNCTION__,
                xdpi, ydpi );
        return -1;
    }

    *px_dpi = xdpi;
    *py_dpi = ydpi;

    return 0;
}
Exemplo n.º 7
0
void		init_env(t_mlx *f)
{
	f->wid = WID;
	f->hig = HIG;
	FF(r) = 5;
	FF(g) = 10;
	FF(b) = 5;
	FF(zoom) = 0;
	f->crt_img = 0;
	FF(julia) = 1;
	f->motion = 0;
	f->mlx = mlx_init();
	f->win = mlx_new_window(f->mlx, f->wid, f->hig, f->name);
	ini_img(f);
}
Exemplo n.º 8
0
void TFfGGen::GenFFGraphs(const double& FProb, const double& BProb, const TStr& FNm) {
	const int NRuns = 10;
	const int NNodes = 10000;
	TGStat::NDiamRuns = 10;
	//const double FProb = 0.35, BProb = 0.20;  // ff1
	//const double FProb = 0.37, BProb = 0.32;  // ff2
	//const double FProb = 0.37, BProb = 0.325; // ff22
	//const double FProb = 0.37, BProb = 0.33;  // ff3
	//const double FProb = 0.37, BProb = 0.35;  // ff4
	//const double FProb = 0.38, BProb = 0.35;  // ff5
	TVec<PGStatVec> GAtTmV;
	TFfGGen FF(false, 1, FProb, BProb, 1.0, 0, 0);
	for (int r = 0; r < NRuns; r++) {
		PGStatVec GV = TGStatVec::New(tmuNodes, TGStat::AllStat());
		FF.GenGraph(NNodes, GV, true);
		for (int i = 0; i < GV->Len(); i++) {
			if (i == GAtTmV.Len()) {
				GAtTmV.Add(TGStatVec::New(tmuNodes, TGStat::AllStat()));
			}
			GAtTmV[i]->Add(GV->At(i));
		}
		IAssert(GAtTmV.Len() == GV->Len());
	}
	PGStatVec AvgStat = TGStatVec::New(tmuNodes, TGStat::AllStat());
	for (int i = 0; i < GAtTmV.Len(); i++) {
		AvgStat->Add(GAtTmV[i]->GetAvgGStat(false));
	}
	AvgStat->PlotAllVsX(gsvNodes, FNm, TStr::Fmt("Forest Fire: F:%g  B:%g (%d runs)", FProb, BProb, NRuns));
	AvgStat->Last()->PlotAll(FNm, TStr::Fmt("Forest Fire: F:%g  B:%g (%d runs)", FProb, BProb, NRuns));
}
Exemplo n.º 9
0
void load_calibration_file(int N) {
	QString path=QString("%1/isosplit_calibration_%2.txt").arg(s_calibration_dir).arg(N);
	QFile FF(path);
	if (FF.open(QFile::ReadOnly|QFile::Text)) {
		QString txt=QString(FF.readAll());
		FF.close();
		QList<QString> lines=txt.split("\n");
		if (lines.count()>10) {
			calibration_file CF;
			CF.curve_len=lines[0].toInt();
			CF.num_trials=lines[1].toInt();
			for (int j=0; j<CF.curve_len; j++) {
				QString line=lines.value(2+j);
				QList<QString> tmp=line.split(",");
				if (tmp.count()!=2) return;
				CF.avg << tmp.value(0).toDouble();
				CF.stdev << tmp.value(1).toDouble();
			}
			for (int j=0; j<CF.num_trials; j++) {
				QString line=lines.value(2+CF.curve_len+j);
				CF.scores << line.toDouble();
			}
			s_calibration_files[N]=CF;
		}
		else return;
	}

}
Exemplo n.º 10
0
/* common */
static void *qesd_audio_init (void)
{
    void*    result = NULL;

    D("%s: entering", __FUNCTION__);

    if (esd_lib == NULL) {
        int  fd;

        esd_lib = dlopen( "libesd.so", RTLD_NOW );
        if (esd_lib == NULL)
            esd_lib = dlopen( "libesd.so.0", RTLD_NOW );

        if (esd_lib == NULL) {
            D("could not find libesd on this system");
            goto Exit;
        }

        if (esd_dynlink_init(esd_lib) < 0)
            goto Fail;

        fd = FF(esd_open_sound)(conf.dac_host);
        if (fd < 0) {
            D("%s: could not open direct sound server connection, trying localhost",
              __FUNCTION__);
            fd = FF(esd_open_sound)("localhost");
            if (fd < 0) {
                D("%s: could not open localhost sound server connection", __FUNCTION__);
                goto Fail;
            }
        }

        D("%s: EsounD server connection succeeded", __FUNCTION__);
        /* FF(esd_close)(fd); */
    }
    result = &conf;
    goto Exit;

Fail:
    D("%s: failed to open library", __FUNCTION__);
    dlclose(esd_lib);
    esd_lib = NULL;

Exit:
    return  result;
}
QString read_text_file(QString path) {
	QFile FF(path);
	if (!FF.open(QFile::Text|QFile::ReadOnly)) {
		return "";
	}
	QString ret=QString(FF.readAll());
	FF.close();
	return ret;
}
Exemplo n.º 12
0
	void push(const std::shared_ptr<AVFrame>& frame)
	{		
		if (fast_path())
			fast_path_.push(frame);
		else
			FF(av_buffersrc_add_frame(
				video_graph_in_, 
				frame.get()));
	}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//    freopen("textout.txt", "w", stdout);
#endif
    while(scanf("%d %d",&n,&m)!=EOF){
        int num11=0,num10=0,num01=0,num00=0;
        for(i=0;i<n;i++)
            for(j=0;j<m;j++){
                scanf("%s",f[i][j].a);
                if(f[i][j].a[0]=='1' && f[i][j].a[1]=='1') num11++;
                else if(f[i][j].a[0]=='1' && f[i][j].a[1]=='0') num10++;
                else if(f[i][j].a[0]=='0' && f[i][j].a[1]=='1') num01++;
                else num00++;

            }
        i=1;j=1;flag=1;
        FF(num11,"11");
        //FF(num10,i,j,flag,"10");
        //FF(num01,i,j,flag,"01");
        int ii,jj;num10=num10+num01;
        char aa[3]="10",bb[3]="01";
        ii=i;jj=j;
        while(num10--){
            if(num10==-1) break;
            if(ii==1 || f[ii-1][jj].a[0]=='0' ||(f[ii-1][jj].a[0]=='1' && f[ii-1][jj].a[1]=='1') )
                strcpy(f[ii][jj].a,aa);
            else strcpy(f[ii][jj].a,bb);
            if(flag==1){
                jj++;
                if(jj==(m+1)){ii++;jj=m;flag=2;}
            }
            else{
                jj--;
                if(jj==0){ii++;jj=1;flag=1;}
            }
        }
        i=ii;j=jj;
        FF(num00,"00");
        Print();
    }
    return 0;
}
Exemplo n.º 14
0
static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...)
{
    va_list ap;

    va_start (ap, fmt);
    AUD_vlog (AUDIO_CAP, fmt, ap);
    va_end (ap);

    AUD_log (AUDIO_CAP, "Reason: %s\n", FF(pa_strerror) (err));
}
Exemplo n.º 15
0
void FF(int i,int j)
{
	int k;
	for(k=0;k<4;k++)
		if( !(map[i][j] & wall[k]) && !room[i+dir[k][0]][j+dir[k][1]]){
			room[i+dir[k][0]][j+dir[k][1]]=num;
			count[num]++;
			FF(i+dir[k][0],j+dir[k][1]);
		}
}
Exemplo n.º 16
0
int FAR_FileRead(farfile_t hFile, void* buffer, int size)
{
	FARfileobj_t* pFile = FF(hFile);
	int* pPos = &pFile->pos;
	FAR_RawSeek(pFile->a, pFile->base + *pPos, SEEK_SET);
	int diff = pFile->size - *pPos;
	if (size > diff) size = diff;
	int rc = FAR_RawRead(pFile->a, buffer, size);
	*pPos += rc;
	return rc;
}
Exemplo n.º 17
0
		void	compress(sm3_data_picker& data){

			boost::uint32_t A= ctx_.hash32[0];
			boost::uint32_t B= ctx_.hash32[1];
			boost::uint32_t C= ctx_.hash32[2];
			boost::uint32_t D= ctx_.hash32[3];
			boost::uint32_t E= ctx_.hash32[4];
			boost::uint32_t F= ctx_.hash32[5];
			boost::uint32_t G= ctx_.hash32[6];
			boost::uint32_t H= ctx_.hash32[7];

			boost::uint32_t SS1=0, SS2=0, TT1=0, TT2=0;
			boost::uint32_t W[64+4]={0},W1[64]={0};
			for (int i=0;i<16;++i){
				W[i]=data.next_uint32_be();
			}

			for (int j = 16; j < 68; j++) {
				W[j] = P1(W[j - 16] ^ W[j - 9] ^ circular_shift_l<boost::uint32_t>(W[j - 3],15)) ^ circular_shift_l<boost::uint32_t>(W[j - 13],7) ^ W[j - 6] ;
			}

			for (int j = 0; j < 64; j++) {
				W1[j] = W[j] ^ W[j + 4];
			}
			for (int j = 0; j < 64; j++) {
				SS1 =circular_shift_l<boost::uint32_t>(
					(circular_shift_l<boost::uint32_t>(A,12) + E + circular_shift_l<boost::uint32_t>(get_magic_number(j),j) )
					,7);
				SS2 = SS1 ^ circular_shift_l<boost::uint32_t>(A,12);
				TT1 = FF(A, B, C, j) + D + SS2 + W1[j];
				unsigned long ggh=GG(E,F,G,j);
				TT2 = GG(E, F, G, j) + H + SS1 + W[j];
				D = C;
				C = circular_shift_l<boost::uint32_t>(B,9);
				B = A;
				A = TT1;
				H = G;
				G = circular_shift_l<boost::uint32_t>(F,19);
				F = E;
				E = P0(TT2);
			}

			ctx_.hash32[0] ^=A;
			ctx_.hash32[1] ^=B;
			ctx_.hash32[2] ^=C;
			ctx_.hash32[3] ^=D;
			ctx_.hash32[4] ^=E;
			ctx_.hash32[5] ^=F;
			ctx_.hash32[6] ^=G;
			ctx_.hash32[7] ^=H;
		}
Exemplo n.º 18
0
std::shared_ptr<AVFrame> make_av_audio_frame(const core::const_frame& frame, const core::video_format_desc& format_desc)
{
    auto av_frame = alloc_frame();

    const auto& buffer = frame.audio_data();

    // TODO (fix) Use sample_format_desc.
    av_frame->channels       = format_desc.audio_channels;
    av_frame->channel_layout = av_get_default_channel_layout(av_frame->channels);
    av_frame->sample_rate    = format_desc.audio_sample_rate;
    av_frame->format         = AV_SAMPLE_FMT_S32;
    av_frame->nb_samples     = static_cast<int>(buffer.size() / av_frame->channels);
    FF(av_frame_get_buffer(av_frame.get(), 32));
    std::memcpy(av_frame->data[0], buffer.data(), buffer.size() * sizeof(buffer.data()[0]));

    return av_frame;
}
Exemplo n.º 19
0
void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){

  static String tmps = "";

  if(type == WS_EVT_CONNECT){
    //client connected
    DEBUG_MSG_OPAQWEBSOCKET(FF("ws[%s][%u] connect\n"), server->url(), client->id());
    //client->printf("Hello Client %u :)", client->id());
    client->ping();
  } else if(type == WS_EVT_DISCONNECT){
    //client disconnected
    DEBUG_MSG_OPAQWEBSOCKET(FF("ws[%s][%u] disconnect: %u\n"), server->url(), client->id());
  } else if(type == WS_EVT_ERROR){
    //error was received from the other end
    DEBUG_MSG_OPAQWEBSOCKET(FF("ws[%s][%u] error(%u): %s\n"), server->url(), client->id(), *((uint16_t*)arg), (char*)data);
  } else if(type == WS_EVT_PONG){
    //pong message was received (in response to a ping request maybe)
    DEBUG_MSG_OPAQWEBSOCKET(FF("ws[%s][%u] pong[%u]: %s\n"), server->url(), client->id(), len, (len)?(char*)data:"");
  } else if(type == WS_EVT_DATA){
    //data packet
    AwsFrameInfo * info = (AwsFrameInfo*)arg;
    if(info->final && info->index == 0 && info->len == len){
      //the whole message is in a single frame and we got all of it's data
      DEBUG_MSG_OPAQWEBSOCKET(FF("ws[%s][%u] %s-message[%llu]: "), server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len);
      if(info->opcode == WS_TEXT){
        data[len] = 0;
        DEBUG_MSG_OPAQWEBSOCKET(FF("%s\n"), (char*)data);

        parseTextMessage(client, data, len);
        
      } else {
        for(size_t i=0; i < info->len; i++){
          DEBUG_MSG_OPAQWEBSOCKET(FF("%02x "), data[i]);
        }
        DEBUG_MSG_OPAQWEBSOCKET(FF("\n"));
      }

      
    } else {
      //message is comprised of multiple frames or the frame is split into multiple packets
      if(info->index == 0){
Exemplo n.º 20
0
static void qpa_fini_in (HWVoiceIn *hw)
{
    void *ret;
    PAVoiceIn *pa = (PAVoiceIn *) hw;

    audio_pt_lock (&pa->pt, AUDIO_FUNC);
    pa->done = 1;
    audio_pt_unlock_and_signal (&pa->pt, AUDIO_FUNC);
    audio_pt_join (&pa->pt, &ret, AUDIO_FUNC);

    if (pa->s) {
        FF(pa_simple_free) (pa->s);
        pa->s = NULL;
    }

    audio_pt_fini (&pa->pt, AUDIO_FUNC);
    qemu_free (pa->pcm_buf);
    pa->pcm_buf = NULL;
}
Exemplo n.º 21
0
int main()
{
	FILE *fin,*fout;
	int M,N;
	int i,j,x,y;
	char d;
	int ans=0,big=0;
	fin = fopen("castle.in","r");
	fout = fopen("castle.out","w");
	fscanf(fin,"%d%d",&M,&N);
	for(i=0;i<N;i++)
		for(j=0;j<M;j++)
			fscanf(fin,"%d",&map[i][j]);
	memset(room,0,sizeof(room));
	memset(count,0,sizeof(count));
	for(i=0;i<N;i++)
		for(j=0;j<M;j++)
			if(!room[i][j]){
				num++;
				room[i][j]=num;
				count[num]++;
				FF(i,j);
				if(count[num]>big)
					big=count[num];
			}
	for(i=0;i<M;i++)
		for(j=N-1;j>=0;j--){
			if(j!=0 && (room[j][i] != room[j-1][i]) && (count[room[j][i]]+count[room[j-1][i]] >ans)){
				ans=count[room[j][i]]+count[room[j-1][i]];
				x=j,y=i;
				d='N';
			}
			if(i!=M-1 && (room[j][i] != room[j][i+1]) && (count[room[j][i]]+count[room[j][i+1]] >ans)){
				ans = count[room[j][i]] + count[room[j][i+1]];	
				x=j,y=i;
				d='E';
			}
		}
	fprintf(fout,"%d\n%d\n%d\n",num,big,ans);
	fprintf(fout,"%d %d %c\n",x+1,y+1,d);
	return 0;
}
Exemplo n.º 22
0
int FAR_FileSeek(farfile_t hFile, int pos, int mode)
{
	FARfileobj_t* pFile = FF(hFile);
	int size = pFile->size;
	switch (mode)
	{
		case SEEK_SET:
			break;
		case SEEK_CUR:
			pos += pFile->pos;
			break;
		case SEEK_END:
			pos += pFile->size;
			break;
	}
	if (pos > size) pos = size;
	if (pos < 0) pos = 0;
	pFile->pos = pos;
	return pos;
}
Exemplo n.º 23
0
QString compute_the_file_hash(const QString& path, int num_bytes)
{
    // Do not printf here!
    QCryptographicHash hash(QCryptographicHash::Sha1);
    QFile FF(path);
    if (!FF.open(QFile::ReadOnly))
        return "";
    int num_bytes_processed = 0;
    while ((!FF.atEnd()) && ((num_bytes == 0) || (num_bytes_processed < num_bytes))) {
        QByteArray tmp = FF.read(10000);
        if (num_bytes != 0) {
            if (num_bytes_processed + tmp.count() > num_bytes) {
                tmp = tmp.mid(0, num_bytes - num_bytes_processed);
            }
        }
        hash.addData(tmp);
        num_bytes_processed += tmp.count();
    }

    QString ret = QString(hash.result().toHex());
    return ret;
}
Exemplo n.º 24
0
int main(int argc, char* argv[]) {
  printf("ForestFire. build: %s, %s. Start time: %s\n\n", __TIME__, __DATE__, TExeTm::GetCurTm());
  Env = TEnv(argc, argv, TNotify::StdNotify);
  Env.PrepArgs("Forest Fire");
  TExeTm ExeTm;
  Try
  const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "graph.txt", "Output graph file name");
  const int NNodes = Env.GetIfArgPrefixInt("-n:", 10000, "Number of nodes (size of the generated graph)");
  const double FwdProb = Env.GetIfArgPrefixFlt("-f:", 0.35, "Forward burning probability");
  const double BckProb = Env.GetIfArgPrefixFlt("-b:", 0.32, "Backward burning probability");
  const int StartNodes = Env.GetIfArgPrefixInt("-s:", 1, "Start graph with S isolated nodes");
  const double Take2AmbProb = Env.GetIfArgPrefixFlt("-a:", 0.0, "Probability of a new node choosing 2 ambassadors");
  const double OrphanProb = Env.GetIfArgPrefixFlt("-op:", 0.0, "Probability of a new node being an orphan (node with zero out-degree)");
  // generate forest fire graph
  TFfGGen::TimeLimitSec = -1;
  TFfGGen FF(false, StartNodes, FwdProb, BckProb, 1.0, Take2AmbProb, OrphanProb);
  FF.GenGraph(NNodes, false);
  TSnap::SaveEdgeList(FF.GetGraph(), OutFNm, FF.GetParamStr());
  Catch
  printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  return 0;
}
Exemplo n.º 25
0
void		display(t_mlx *f)
{
	mlx_string_put(f->mlx, f->win, 5, 1, BLANC, "Fractal :");
	mlx_string_put(f->mlx, f->win, 100, 1, BLANC, f->name);
	if (ft_strcmp(f->name, "Julia") == 0)
		mlx_string_put(f->mlx, f->win, 160, 1, BLANC, ft_itoa(FF(julia)));
	mlx_string_put(f->mlx, f->win, 5, 26, BLANC, "Iterate (</>):");
	mlx_string_put(f->mlx, f->win, 160, 26, BLANC, ft_itoa(FF(it)));
	mlx_string_put(f->mlx, f->win, 5, 46, BLANC, "Zoom (-/+):");
	mlx_string_put(f->mlx, f->win, 130, 46, BLANC, ft_itoa(FF(zoom)));
	mlx_string_put(f->mlx, f->win, 5, 66, BLANC, "Rouge (E-/R+):");
	mlx_string_put(f->mlx, f->win, 160, 66, BLANC, ft_itoa(FF(r)));
	mlx_string_put(f->mlx, f->win, 5, 86, BLANC, "Vert (F-/G+):");
	mlx_string_put(f->mlx, f->win, 160, 86, BLANC, ft_itoa(FF(g)));
	mlx_string_put(f->mlx, f->win, 5, 106, BLANC, "Bleu (V-/B+):");
	mlx_string_put(f->mlx, f->win, 160, 106, BLANC, ft_itoa(FF(b)));
}
Exemplo n.º 26
0
void TNetInfBs::GenerateGroundTruth(const int& TNetwork, const int& NNodes, const int& NEdges, const TStr& NetworkParams) {
	  TKronMtx SeedMtx;
	  TStr MtxNm;

	  switch (TNetwork) {
	  // 2-dimension kronecker network
	  case 0:
		  printf("Kronecker graph for Ground Truth\n");
		  SeedMtx = TKronMtx::GetMtx(NetworkParams.CStr()); // 0.5,0.5,0.5,0.5

		  printf("\n*** Seed matrix:\n");
		  SeedMtx.Dump();

		  GroundTruth = TKronMtx::GenFastKronecker(SeedMtx, (int)TMath::Log2(NNodes), NEdges, true, 0);

		  break;

	  // forest fire network
	  case 1:
		  printf("Forest Fire graph for Ground Truth\n");
		  TStrV NetworkParamsV; NetworkParams.SplitOnAllCh(';', NetworkParamsV);

		  TFfGGen FF(true, // BurnExpFireP
					 NetworkParamsV[0].GetInt(), // StartNNodes (1)
					 NetworkParamsV[1].GetFlt(), // ForwBurnProb (0.2)
					 NetworkParamsV[2].GetFlt(), // BackBurnProb (0.17)
					 NetworkParamsV[3].GetInt(), // DecayProb (1)
					 NetworkParamsV[4].GetInt(), // Take2AmbasPrb (0)
					 NetworkParamsV[5].GetInt()); // OrphanPrb (0)

		  FF.GenGraph(NNodes, false);
		  GroundTruth = FF.GetGraph();

		  break;
	  }
}
Exemplo n.º 27
0
static int  md4_compress(hash_state *md, unsigned char *buf)
#endif
{
    ulong32 x[16], a, b, c, d;
    int i;

    /* copy state */
    a = md->md4.state[0];
    b = md->md4.state[1];
    c = md->md4.state[2];
    d = md->md4.state[3];

    /* copy the state into 512-bits into W[0..15] */
    for (i = 0; i < 16; i++) {
        LOAD32L(x[i], buf + (4*i));
    }

    /* Round 1 */
    FF (a, b, c, d, x[ 0], S11); /* 1 */
    FF (d, a, b, c, x[ 1], S12); /* 2 */
    FF (c, d, a, b, x[ 2], S13); /* 3 */
    FF (b, c, d, a, x[ 3], S14); /* 4 */
    FF (a, b, c, d, x[ 4], S11); /* 5 */
    FF (d, a, b, c, x[ 5], S12); /* 6 */
    FF (c, d, a, b, x[ 6], S13); /* 7 */
    FF (b, c, d, a, x[ 7], S14); /* 8 */
    FF (a, b, c, d, x[ 8], S11); /* 9 */
    FF (d, a, b, c, x[ 9], S12); /* 10 */
    FF (c, d, a, b, x[10], S13); /* 11 */
    FF (b, c, d, a, x[11], S14); /* 12 */
    FF (a, b, c, d, x[12], S11); /* 13 */
    FF (d, a, b, c, x[13], S12); /* 14 */
    FF (c, d, a, b, x[14], S13); /* 15 */
    FF (b, c, d, a, x[15], S14); /* 16 */

    /* Round 2 */
    GG (a, b, c, d, x[ 0], S21); /* 17 */
    GG (d, a, b, c, x[ 4], S22); /* 18 */
    GG (c, d, a, b, x[ 8], S23); /* 19 */
    GG (b, c, d, a, x[12], S24); /* 20 */
    GG (a, b, c, d, x[ 1], S21); /* 21 */
    GG (d, a, b, c, x[ 5], S22); /* 22 */
    GG (c, d, a, b, x[ 9], S23); /* 23 */
    GG (b, c, d, a, x[13], S24); /* 24 */
    GG (a, b, c, d, x[ 2], S21); /* 25 */
    GG (d, a, b, c, x[ 6], S22); /* 26 */
    GG (c, d, a, b, x[10], S23); /* 27 */
    GG (b, c, d, a, x[14], S24); /* 28 */
    GG (a, b, c, d, x[ 3], S21); /* 29 */
    GG (d, a, b, c, x[ 7], S22); /* 30 */
    GG (c, d, a, b, x[11], S23); /* 31 */
    GG (b, c, d, a, x[15], S24); /* 32 */

    /* Round 3 */
    HH (a, b, c, d, x[ 0], S31); /* 33 */
    HH (d, a, b, c, x[ 8], S32); /* 34 */
    HH (c, d, a, b, x[ 4], S33); /* 35 */
    HH (b, c, d, a, x[12], S34); /* 36 */
    HH (a, b, c, d, x[ 2], S31); /* 37 */
    HH (d, a, b, c, x[10], S32); /* 38 */
    HH (c, d, a, b, x[ 6], S33); /* 39 */
    HH (b, c, d, a, x[14], S34); /* 40 */
    HH (a, b, c, d, x[ 1], S31); /* 41 */
    HH (d, a, b, c, x[ 9], S32); /* 42 */
    HH (c, d, a, b, x[ 5], S33); /* 43 */
    HH (b, c, d, a, x[13], S34); /* 44 */
    HH (a, b, c, d, x[ 3], S31); /* 45 */
    HH (d, a, b, c, x[11], S32); /* 46 */
    HH (c, d, a, b, x[ 7], S33); /* 47 */
    HH (b, c, d, a, x[15], S34); /* 48 */


    /* Update our state */
    md->md4.state[0] = md->md4.state[0] + a;
    md->md4.state[1] = md->md4.state[1] + b;
    md->md4.state[2] = md->md4.state[2] + c;
    md->md4.state[3] = md->md4.state[3] + d;

    return CRYPT_OK;
}
Exemplo n.º 28
0
gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
                           int nfile, t_filenm fnm[], int npargs, t_pargs *pa,
                           int ndesc, const char **desc,
                           int nbugs, const char **bugs,
                           gmx_output_env_t **oenv)
{
    /* This array should match the order of the enum in oenv.h */
    const char *const xvg_formats[] = { "xmgrace", "xmgr", "none" };

    // Handle the flags argument, which is a bit field
    // The FF macro returns whether or not the bit is set
#define FF(arg) ((Flags & arg) == arg)

    try
    {
        double                          tbegin        = 0.0, tend = 0.0, tdelta = 0.0;
        bool                            bBeginTimeSet = false, bEndTimeSet = false, bDtSet = false;
        bool                            bView         = false;
        int                             xvgFormat     = 0;
        gmx::OptionsAdapter             adapter(*argc, argv);
        gmx::Options                    options(NULL, NULL);
        gmx::OptionsBehaviorCollection  behaviors(&options);
        gmx::FileNameOptionManager      fileOptManager;

        fileOptManager.disableInputOptionChecking(
                FF(PCA_NOT_READ_NODE) || FF(PCA_DISABLE_INPUT_FILE_CHECKING));
        options.addManager(&fileOptManager);

        if (FF(PCA_CAN_SET_DEFFNM))
        {
            fileOptManager.addDefaultFileNameOption(&options, "deffnm");
        }
        if (FF(PCA_CAN_BEGIN))
        {
            options.addOption(
                    gmx::DoubleOption("b")
                        .store(&tbegin).storeIsSet(&bBeginTimeSet).timeValue()
                        .description("First frame (%t) to read from trajectory"));
        }
        if (FF(PCA_CAN_END))
        {
            options.addOption(
                    gmx::DoubleOption("e")
                        .store(&tend).storeIsSet(&bEndTimeSet).timeValue()
                        .description("Last frame (%t) to read from trajectory"));
        }
        if (FF(PCA_CAN_DT))
        {
            options.addOption(
                    gmx::DoubleOption("dt")
                        .store(&tdelta).storeIsSet(&bDtSet).timeValue()
                        .description("Only use frame when t MOD dt = first time (%t)"));
        }
        gmx::TimeUnit  timeUnit = gmx::TimeUnit_Default;
        if (FF(PCA_TIME_UNIT))
        {
            std::shared_ptr<gmx::TimeUnitBehavior> timeUnitBehavior(
                    new gmx::TimeUnitBehavior());
            timeUnitBehavior->setTimeUnitStore(&timeUnit);
            timeUnitBehavior->setTimeUnitFromEnvironment();
            timeUnitBehavior->addTimeUnitOption(&options, "tu");
            behaviors.addBehavior(timeUnitBehavior);
        }
        if (FF(PCA_CAN_VIEW))
        {
            options.addOption(
                    gmx::BooleanOption("w").store(&bView)
                        .description("View output [REF].xvg[ref], [REF].xpm[ref], "
                                     "[REF].eps[ref] and [REF].pdb[ref] files"));
        }

        bool bXvgr = false;
        for (int i = 0; i < nfile; i++)
        {
            bXvgr = bXvgr || (fnm[i].ftp == efXVG);
        }
        xvgFormat = gmx::getDefaultXvgFormat(xvg_formats);
        if (bXvgr)
        {
            options.addOption(
                    gmx::EnumIntOption("xvg").enumValue(xvg_formats)
                        .store(&xvgFormat)
                        .description("xvg plot formatting"));
        }

        /* Now append the program specific arguments */
        for (int i = 0; i < nfile; i++)
        {
            adapter.filenmToOptions(&options, &fnm[i]);
        }
        for (int i = 0; i < npargs; i++)
        {
            adapter.pargsToOptions(&options, &pa[i]);
        }

        const gmx::CommandLineHelpContext *context =
            gmx::GlobalCommandLineHelpContext::get();
        if (context != NULL)
        {
            GMX_RELEASE_ASSERT(gmx_node_rank() == 0,
                               "Help output should be handled higher up and "
                               "only get called only on the master rank");
            gmx::CommandLineHelpWriter(options)
                .setHelpText(gmx::constArrayRefFromArray<const char *>(desc, ndesc))
                .setKnownIssues(gmx::constArrayRefFromArray(bugs, nbugs))
                .writeHelp(*context);
            return FALSE;
        }

        /* Now parse all the command-line options */
        gmx::CommandLineParser(&options).skipUnknown(FF(PCA_NOEXIT_ON_ARGS))
            .parse(argc, argv);
        behaviors.optionsFinishing();
        options.finish();

        /* set program name, command line, and default values for output options */
        output_env_init(oenv, gmx::getProgramContext(),
                        (time_unit_t)(timeUnit + 1), bView,
                        (xvg_format_t)(xvgFormat + 1), 0);

        /* Extract Time info from arguments */
        if (bBeginTimeSet)
        {
            setTimeValue(TBEGIN, tbegin);
        }
        if (bEndTimeSet)
        {
            setTimeValue(TEND, tend);
        }
        if (bDtSet)
        {
            setTimeValue(TDELTA, tdelta);
        }

        adapter.copyValues(!FF(PCA_NOT_READ_NODE));

        return TRUE;
    }
    GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
#undef FF
}
Exemplo n.º 29
0
void md4_process_block(uint32_t state[4], const uint32_t block[MD4_BLOCK_SIZE / 4])
{
    unsigned a, b, c, d;
    a = state[0];
    b = state[1];
    c = state[2];
    d = state[3];

    FF(a, b, c, d, block[0], 3);   /* 1 */
    FF(d, a, b, c, block[1], 7);   /* 2 */
    FF(c, d, a, b, block[2], 11);  /* 3 */
    FF(b, c, d, a, block[3], 19);  /* 4 */
    FF(a, b, c, d, block[4], 3);   /* 5 */
    FF(d, a, b, c, block[5], 7);   /* 6 */
    FF(c, d, a, b, block[6], 11);  /* 7 */
    FF(b, c, d, a, block[7], 19);  /* 8 */
    FF(a, b, c, d, block[8], 3);   /* 9 */
    FF(d, a, b, c, block[9], 7);   /* 10 */
    FF(c, d, a, b, block[10], 11); /* 11 */
    FF(b, c, d, a, block[11], 19); /* 12 */
    FF(a, b, c, d, block[12], 3);  /* 13 */
    FF(d, a, b, c, block[13], 7);  /* 14 */
    FF(c, d, a, b, block[14], 11); /* 15 */
    FF(b, c, d, a, block[15], 19); /* 16 */

    GG(a, b, c, d, block[0], 3);   /* 17 */
    GG(d, a, b, c, block[4], 5);   /* 18 */
    GG(c, d, a, b, block[8], 9);   /* 19 */
    GG(b, c, d, a, block[12], 13); /* 20 */
    GG(a, b, c, d, block[1], 3);   /* 21 */
    GG(d, a, b, c, block[5], 5);   /* 22 */
    GG(c, d, a, b, block[9], 9);   /* 23 */
    GG(b, c, d, a, block[13], 13); /* 24 */
    GG(a, b, c, d, block[2], 3);   /* 25 */
    GG(d, a, b, c, block[6], 5);   /* 26 */
    GG(c, d, a, b, block[10], 9);  /* 27 */
    GG(b, c, d, a, block[14], 13); /* 28 */
    GG(a, b, c, d, block[3], 3);   /* 29 */
    GG(d, a, b, c, block[7], 5);   /* 30 */
    GG(c, d, a, b, block[11], 9);  /* 31 */
    GG(b, c, d, a, block[15], 13); /* 32 */

    HH(a, b, c, d, block[0], 3);   /* 33 */
    HH(d, a, b, c, block[8], 9);   /* 34 */
    HH(c, d, a, b, block[4], 11);  /* 35 */
    HH(b, c, d, a, block[12], 15); /* 36 */
    HH(a, b, c, d, block[2], 3);   /* 37 */
    HH(d, a, b, c, block[10], 9);  /* 38 */
    HH(c, d, a, b, block[6], 11);  /* 39 */
    HH(b, c, d, a, block[14], 15); /* 40 */
    HH(a, b, c, d, block[1], 3);   /* 41 */
    HH(d, a, b, c, block[9], 9);   /* 42 */
    HH(c, d, a, b, block[5], 11);  /* 43 */
    HH(b, c, d, a, block[13], 15); /* 44 */
    HH(a, b, c, d, block[3], 3);   /* 45 */
    HH(d, a, b, c, block[11], 9);  /* 46 */
    HH(c, d, a, b, block[7], 11);  /* 47 */
    HH(b, c, d, a, block[15], 15); /* 48 */

    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;
}
Exemplo n.º 30
0
/*
* MD5 Compression Function
*/
void MD5::compress_n(const byte input[], size_t blocks)
   {
   u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3];

   for(size_t i = 0; i != blocks; ++i)
      {
      load_le(&M[0], input, M.size());

      FF(A,B,C,D,M[ 0], 7,0xD76AA478);   FF(D,A,B,C,M[ 1],12,0xE8C7B756);
      FF(C,D,A,B,M[ 2],17,0x242070DB);   FF(B,C,D,A,M[ 3],22,0xC1BDCEEE);
      FF(A,B,C,D,M[ 4], 7,0xF57C0FAF);   FF(D,A,B,C,M[ 5],12,0x4787C62A);
      FF(C,D,A,B,M[ 6],17,0xA8304613);   FF(B,C,D,A,M[ 7],22,0xFD469501);
      FF(A,B,C,D,M[ 8], 7,0x698098D8);   FF(D,A,B,C,M[ 9],12,0x8B44F7AF);
      FF(C,D,A,B,M[10],17,0xFFFF5BB1);   FF(B,C,D,A,M[11],22,0x895CD7BE);
      FF(A,B,C,D,M[12], 7,0x6B901122);   FF(D,A,B,C,M[13],12,0xFD987193);
      FF(C,D,A,B,M[14],17,0xA679438E);   FF(B,C,D,A,M[15],22,0x49B40821);

      GG(A,B,C,D,M[ 1], 5,0xF61E2562);   GG(D,A,B,C,M[ 6], 9,0xC040B340);
      GG(C,D,A,B,M[11],14,0x265E5A51);   GG(B,C,D,A,M[ 0],20,0xE9B6C7AA);
      GG(A,B,C,D,M[ 5], 5,0xD62F105D);   GG(D,A,B,C,M[10], 9,0x02441453);
      GG(C,D,A,B,M[15],14,0xD8A1E681);   GG(B,C,D,A,M[ 4],20,0xE7D3FBC8);
      GG(A,B,C,D,M[ 9], 5,0x21E1CDE6);   GG(D,A,B,C,M[14], 9,0xC33707D6);
      GG(C,D,A,B,M[ 3],14,0xF4D50D87);   GG(B,C,D,A,M[ 8],20,0x455A14ED);
      GG(A,B,C,D,M[13], 5,0xA9E3E905);   GG(D,A,B,C,M[ 2], 9,0xFCEFA3F8);
      GG(C,D,A,B,M[ 7],14,0x676F02D9);   GG(B,C,D,A,M[12],20,0x8D2A4C8A);

      HH(A,B,C,D,M[ 5], 4,0xFFFA3942);   HH(D,A,B,C,M[ 8],11,0x8771F681);
      HH(C,D,A,B,M[11],16,0x6D9D6122);   HH(B,C,D,A,M[14],23,0xFDE5380C);
      HH(A,B,C,D,M[ 1], 4,0xA4BEEA44);   HH(D,A,B,C,M[ 4],11,0x4BDECFA9);
      HH(C,D,A,B,M[ 7],16,0xF6BB4B60);   HH(B,C,D,A,M[10],23,0xBEBFBC70);
      HH(A,B,C,D,M[13], 4,0x289B7EC6);   HH(D,A,B,C,M[ 0],11,0xEAA127FA);
      HH(C,D,A,B,M[ 3],16,0xD4EF3085);   HH(B,C,D,A,M[ 6],23,0x04881D05);
      HH(A,B,C,D,M[ 9], 4,0xD9D4D039);   HH(D,A,B,C,M[12],11,0xE6DB99E5);
      HH(C,D,A,B,M[15],16,0x1FA27CF8);   HH(B,C,D,A,M[ 2],23,0xC4AC5665);

      II(A,B,C,D,M[ 0], 6,0xF4292244);   II(D,A,B,C,M[ 7],10,0x432AFF97);
      II(C,D,A,B,M[14],15,0xAB9423A7);   II(B,C,D,A,M[ 5],21,0xFC93A039);
      II(A,B,C,D,M[12], 6,0x655B59C3);   II(D,A,B,C,M[ 3],10,0x8F0CCC92);
      II(C,D,A,B,M[10],15,0xFFEFF47D);   II(B,C,D,A,M[ 1],21,0x85845DD1);
      II(A,B,C,D,M[ 8], 6,0x6FA87E4F);   II(D,A,B,C,M[15],10,0xFE2CE6E0);
      II(C,D,A,B,M[ 6],15,0xA3014314);   II(B,C,D,A,M[13],21,0x4E0811A1);
      II(A,B,C,D,M[ 4], 6,0xF7537E82);   II(D,A,B,C,M[11],10,0xBD3AF235);
      II(C,D,A,B,M[ 2],15,0x2AD7D2BB);   II(B,C,D,A,M[ 9],21,0xEB86D391);

      A = (digest[0] += A);
      B = (digest[1] += B);
      C = (digest[2] += C);
      D = (digest[3] += D);

      input += hash_block_size();
      }
   }