Ejemplo n.º 1
0
int main() {
    freopen("cifre.in", "r", stdin);
    freopen("cifre.out", "w", stdout);

    scanf("%d%d%d%d", &a, &b, &c, &k);
    int total = b - a + 1;
    punevector(a, va);
    ++b;
    punevector(b, vb);

    dinamica1();

    dinamica2();

    int x = rez(vb) - rez(va);
    if (a == 0 && c == 0)
        ++x;

    printf("%.4lf", (double)x / total);

    return 0;
}
Ejemplo n.º 2
0
MATRICEd *simulateprofiles1(MATRICEd *D, MATRICEd *weights, LISTA *R, GString *f_pr_and, VETTOREd *X0, VETTOREd *Xmin, VETTOREd *Xmax, VETTOREd *lambda, GString *act_fun, VETTOREd *alpha, VETTOREd *beta, double sd_noise, VETTOREd *times, GString *method, MATRICEd *ext_in, LISTA *ext_fun, int save, int rete, int ind_itera, int ko, int pad_reti, int pad_exp, int pad_ko, VETTOREd *param_xmin, VETTOREd *param_xzero, muParserHandle_t *hParsers, double stat_thr, double stat_width, int *stat)
{
	int i;
	VETTOREd *param[MAXPAR];
	enum TIPO tipi[9];
	char etich[50];

	_Intestazione("\n*** simulateprofiles1 ***\n");

	/*
	if(is.null(Rules)) {
		g_Mdiscr<-weights
	        g_ind<-which(g_Mdiscr!=0,arr.g_ind=TRUE)
	        g_Mdiscr[g_ind]<-1
	        ausR<-createRules(g_Mdiscr,f.pr.and)
		Rules<-ausR[[1]]
		max.lengthR<-ausR[[2]]
	        REG<-matrix(0,ncol=max.lengthR,nrow=N)
		max.L<-0
		for (i in (1:N)) {
			aus<-Rules[[i]]
			L<-length(aus)
			if (L>0) REG[i,1:L]<-aus
	   } ...
	*/

	tipi[0] = MATRd;
	tipi[1] = MATRi;
	tipi[2] = VETTd;
	tipi[3] = VETTd;
	tipi[4] = VETTd;
	tipi[5] = STRINGA;
	tipi[6] = MATRd;
	tipi[7] = VETTd;
	if (g_genenet == NULL) {
		CreaLISTA(g_genenet, tipi, 8);
		CtrlLlst(g_genenet, 6);
		CREAstr(ACCEDIlst(g_genenet, 6, str), "");
	}

	/*
	g_M<-weights
	g_Mdiscr<-M
	g_ind<-which(g_M!=0,arr.g_ind=TRUE)
	g_Mdiscr[g_ind]<-1
	g_Mneg<-g_Mdiscr*sign(g_M)
	g_M<-abs(g_M)
	R<-Rules
	*/

	g_ind = which_m_indxne_d(g_ind, weights, 0.0);
	g_Mdiscr = arrotonda_m_d(g_Mdiscr, weights);
	assegna1_ms_indx_i(g_Mdiscr, g_ind, 1);
	g_tmpm1_i = segno_m_d(g_tmpm1_i, weights);
	g_Mneg = moltiplica_mm_i(g_Mneg, g_Mdiscr, g_tmpm1_i);
	g_M = abs_m_d(g_M, weights);

	// genenet<-list(g_M,R,g_Mneg,lambda,alpha,beta,act.fun,EXT.IN,EXT.FUN)
	CtrlSlst(g_genenet, 1);
	ASSEGNAlst(g_genenet, 1, md, g_M);
	CtrlSlst(g_genenet, 2);
	ASSEGNAlst(g_genenet, 2, mi, g_Mneg);
	CtrlSlst(g_genenet, 3);
	ASSEGNAlst(g_genenet, 3, vd, lambda);
	CtrlSlst(g_genenet, 4);
	ASSEGNAlst(g_genenet, 4, vd, alpha);
	CtrlSlst(g_genenet, 5);
	ASSEGNAlst(g_genenet, 5, vd, beta);
	CtrlLlst(g_genenet, 6);
	g_string_assign(ACCEDIlst(g_genenet, 6, str), act_fun->str);
	CtrlSlst(g_genenet, 7);
	ASSEGNAlst(g_genenet, 7, md, ext_in);
	CtrlLlst(g_genenet, 8);
	ASSEGNAlst(g_genenet, 8, vd, Xmin);

	if (!strncmp(method->str, "Euler", 5))
		// D<-dinamica(g_genenet,x0,times)*Xmax
		D = dinamica1(D, g_genenet, R, ext_fun, X0, times, hParsers, stat_thr, stat_width, sd_noise);
	else
		/*
		out<-lsoda(y=x0, times=times, func=dinamica.lsoda, parms=g_genenet, rtol=1e-3, atol=1e-4)
		out.aus<-out[,2:(N+1)]
		D<-t(out.aus)*Xmax
		*/
		D = lsoda1(D, g_genenet, R, ext_fun, X0, times, method->str, 1e-4, 1e-3, hParsers, stat_thr, stat_width, stat, sd_noise);

	moltiplica1_mv_d(D, Xmax);

	if (save == 1) {
		if (ko >= 0)
			snprintf(etich, 50, "SIMdata_simulateprofiles%0*d_%0*d_ko%0*d.txt", pad_reti, rete, pad_exp, ind_itera, pad_ko, ko);
		else
			snprintf(etich, 50, "SIMdata_simulateprofiles%0*d_%0*d.txt", pad_reti, rete, pad_exp, ind_itera);
		write_m_d(etich, D);
	}

	param[LAMBDA] = lambda;
	param[ALPHA] = alpha;
	param[BETA] = beta;
	// fa differenza se non sono esterni, perche' in quel caso sono lunghi 2; salvo Xmin e X0 non normalizzati
	param[XMIN] = param_xmin;
	param[XMAX] = Xmax;
	param[XZERO] = param_xzero;

	if (save == 1) {
		for (i = 0; i < MAXPAR; i++) {
			if (ko >= 0)
				snprintf(etich, 50, "parameters_%s_simulateprofiles%0*d_%0*d_ko%0*d.txt", nomi_param[i], pad_reti, rete, pad_exp, ind_itera, pad_ko, ko);
			else
				snprintf(etich, 50, "parameters_%s_simulateprofiles%0*d_%0*d.txt", nomi_param[i], pad_reti, rete, pad_exp, ind_itera);
			write_vn_d(etich, param[i], nomi_param[i]);
		}
	}

	//~ if (LENGTHlst(R) == 0)
	//~ CancellaLISTA(R1, true);
	//~ CancellaLISTA(genenet, false);
	//~ CANCELLAv_i(g_ind);
	//~ CANCELLAm_d(g_tmpm1_d);
	//~ CANCELLAm_i(g_reg);
	//~ CANCELLAm_d(g_M);
	//~ CANCELLAm_d(g_Mdiscr);
	//~ CANCELLAm_d(g_Mneg);

	StrBilanciam();

	return D;
}