Exemple #1
0
P init(P game, P nazo) {
	h = getLength(fst(game));
	w = getLength(fst(fst(game)));
	randx = 123456;
	turn = 0;
	randomv = 5;
	return P(0, 0);
}
Exemple #2
0
P getfarpoint(int y, int x, P map, int ly, int lx){
	P ret;
	P temp;
	ret = P(0, 0);
	if(atom(map)){}
	else{
		ret = getfarpoint2(y, x, fst(map), ly, lx);
		temp = getfarpoint(y + 1, x, snd(map), ly, lx);
		ret = P(toi(fst(ret)) + toi(fst(temp)), toi(snd(ret)) + toi(snd(temp)));
	}
	return ret;
}
P set_array256_rec(P t, int i, P v, int n) {
  if (n == 0) {
    t = v;
  } else {
    if (i < n) {
      t = P(set_array256_rec(fst(t), i, v, n / 2), snd(t));
    } else {
      t = P(fst(t), set_array256_rec(snd(t), i - n, v, n / 2));
    }
  }
  return t;
}
P set_array2d32_rec(P t, int i, P v, int n) {
  if (n == 0) {
    t = set_array32(t, set_array2d32_rec_j, v);
  } else {
    if (i < n) {
      t = P(set_array2d32_rec(fst(t), i, v, n / 2), snd(t));
    } else {
      t = P(fst(t), set_array2d32_rec(snd(t), i - n, v, n / 2));
    }
  }
  return t;
}
Exemple #5
0
P list_to_array128_rec(P t, int size) {
  P tmp;
  if (atom(t)) {
    t = P(0, 0);
  } else {
    if (size > 1) {
      t = list_to_array128_rec(t, size / 2);
      tmp = list_to_array128_rec(snd(t), size / 2);
      t = P(P(fst(t), fst(tmp)), snd(tmp));
    }
  }
  return t;
}
Exemple #6
0
  /*
    Summary:
      Extracts files from a disc to a given directory

    Parameters:
      disc: Path to the disc to read from
      out_directory: Directory where files will be extracted to
  */
  void extract_files(std::string disc, std::string out_directory)
  {
    //  Get the raw FST data from the disc
    uint32_t fstsize = util::read_big<uint32_t>(disc, Header::Offset::FSTSize);
    uint32_t fstoffset = util::read_big<uint32_t>(disc, Header::Offset::FSTOffset);
    std::vector<uint8_t> fstbin = util::read_file(disc, fstsize, fstoffset);
    std::vector<std::thread> threads;

    //  Create FST object
    fst::FST fst(fstbin);

    for (auto& node : fst.entries())
    {
      std::string path = node.first.substr(2); // Skip the ./ part
      fst::Node entry = node.second;

      if (entry.is_dir())
      {
        std::cout << "Creating directory: " << out_directory << path << std::endl;
        boost::filesystem::create_directories(out_directory + path);
      }
      else
      {
        std::cout << "Writing file: " << out_directory << path << std::endl;

        //threads.push_back(std::thread(std::bind(util::write_file, out_directory + path, util::read_file(disc, entry.data_size(), entry.data_offset()))));
        util::write_file(out_directory + path, util::read_file(disc, entry.data_size(), entry.data_offset()));
      }
    }

    for (auto& thread : threads)
    {
      thread.join();
    }
  }
Exemple #7
0
sysSettings::sysSettings(const wxString &name) : wxConfig(name)
{
	// Open the default settings file
	defaultSettings = NULL;
	if (!settingsIni.IsEmpty())
	{
		wxFileInputStream fst(settingsIni);
		defaultSettings = new wxFileConfig(fst);
	}

	// Convert settings from pre-1.5
	long i, serverCount;
	Read(wxT("Servers/Count"), &serverCount, 0L);
	for (i = 1 ; i <= serverCount ; i++)
	{
		if (moveStringValue(wxT("Servers/Database%d"), wxT("Servers/%d/Database"), i))
		{
			moveStringValue(wxT("Servers/Description%d"), wxT("Servers/%d/Description"), i);
			moveStringValue(wxT("Servers/LastDatabase%d"), wxT("Servers/%d/LastDatabase"), i);
			moveStringValue(wxT("Servers/LastSchema%d"), wxT("Servers/%d/LastSchema"), i);
			moveStringValue(wxT("Servers/Server%d"), wxT("Servers/%d/Server"), i);
			moveStringValue(wxT("Servers/ServiceId%d"), wxT("Servers/%d/ServiceId"), i);
			moveStringValue(wxT("Servers/StorePWD%d"), wxT("Servers/%d/StorePWD"), i);
			moveStringValue(wxT("Servers/Rolename%d"), wxT("Servers/%d/Rolename"), i);
			moveStringValue(wxT("Servers/Username%d"), wxT("Servers/%d/Username"), i);
			moveLongValue(wxT("Servers/Port%d"), wxT("Servers/%d/Port"), i);
			moveLongValue(wxT("Servers/SSL%d"), wxT("Servers/%d/SSL"), i);
		}
	}
}
Exemple #8
0
void VM_DeoptimizeAll::doit() {
  DeoptimizationMarker dm;
  // deoptimize all java threads in the system
  if (DeoptimizeALot) {
    for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) {
      if (thread->has_last_Java_frame()) {
        thread->deoptimize();
      }
    }
  } else if (DeoptimizeRandom) {

    // Deoptimize some selected threads and frames
    int tnum = os::random() & 0x3;
    int fnum =  os::random() & 0x3;
    int tcount = 0;
    for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) {
      if (thread->has_last_Java_frame()) {
        if (tcount++ == tnum)  {
        tcount = 0;
          int fcount = 0;
          // Deoptimize some selected frames.
          // Biased llocking wants a updated register map
          for(StackFrameStream fst(thread, UseBiasedLocking); !fst.is_done(); fst.next()) {
            if (fst.current()->can_be_deoptimized()) {
              if (fcount++ == fnum) {
                fcount = 0;
                Deoptimization::deoptimize(thread, *fst.current(), fst.register_map());
              }
            }
          }
        }
      }
    }
  }
}
Exemple #9
0
P getfarpoint2(int y, int x, P map, int ly, int lx){
	P ret;
	P temp;
	int point;

	ret = P(0, 0);
	if(atom(map)){}
	else{
		point = getPoint(y, x) / 10;
		//point = 0;
		ret = P(point * sign(y - ly), point * sign(x - lx));
		temp = getfarpoint2(y, x + 1, snd(map), ly, lx);
		ret = P(toi(fst(ret)) + toi(fst(temp)), toi(snd(ret)) + toi(snd(temp)));
	}
	return ret;
}
Exemple #10
0
int main() {
  //simple hello World
  printf("Hello World\n");

  //Fahrenheit-Celcius Table
  fst();

  return 0;
}
Exemple #11
0
P list2d_to_array2d128_rec(P l) {
  P t;
  if (atom(l)) {
    t = top(0);
  } else {
    t = P(list_to_array128(fst(l)), list2d_to_array2d128_rec(snd(l)));
  }
  return t;
}
Exemple #12
0
int getNumber2(int x, P map){
	int ret;
	if(x == 0){
		ret = toi(fst(map));
	}
	else{
		ret = getNumber2(x - 1, snd(map));
	}
	return ret;
}
Exemple #13
0
int getNumber(int y, int x, P map){
	int ret;
	if(y == 0){
		ret = getNumber2(x, fst(map));
	}
	else
	{
		ret = getNumber(y - 1, x, snd(map));
	}
	return ret;
}
Exemple #14
0
vm::tuple*
agg_configuration::generate_first(void) const
{
   assert(!vals.empty());
   
   const_iterator fst(vals.begin());
   
   assert(fst != vals.end());
   
   simple_tuple *s(*fst);

   return s->get_tuple()->copy();
}
Exemple #15
0
P get_array32(P t, int i) {
  int n = 16;
  while (n > 0) {
    if (i < n) {
      t = fst(t);
    } else {
      t = snd(t);
      i -= n;
    }
    n = n / 2;
  }
  return t;
}
Exemple #16
0
void DiagonalizationPoisson1Dfst(Vector u, const Vector lambda)
{
  Vector btilde = createVector(u->len);
  Vector buf = createVector(4*(u->len+1));
  int i;
  int N=u->len+1;
  int NN=4*N;
  copyVector(btilde, u);
  fst(btilde->data, &N, buf->data, &NN);
  for (i=0;i<btilde->len;++i)
    btilde->data[i] /= (lambda->data[i]+alpha);
  fstinv(btilde->data, &N, buf->data, &NN);
  copyVector(u, btilde);
  freeVector(btilde);
  freeVector(buf);
}
Exemple #17
0
void Test_PG_Output::setUp() {
    Graph fst(4);
    fst[0].label = "h";fst[1].label = "e";fst[2].label = "e";fst[3].label = "e";
    fst[0].id = 10;fst[1].id = 20;fst[2].id = 30;fst[3].id = 40;
    fst[addEdge(0,1,fst).first].label = "p";
    fst[addEdge(1,2,fst).first].label = "m";
    fst[addEdge(2,3,fst).first].label = "m";
    fst[addEdge(3,0,fst).first].label = "m";
    this->f = fst;
    
    Graph sec(5);
    sec[0].label = "h";sec[1].label = "e";sec[2].label = "e";sec[3].label = "e";sec[4].label = "e";
    sec[0].id = 11;sec[1].id = 22;sec[2].id = 33;sec[3].id = 44;sec[4].id = 55;
    sec[addEdge(0,1,sec).first].label = "p";
    sec[addEdge(1,2,sec).first].label = "m";
    sec[addEdge(2,3,sec).first].label = "m";
    sec[addEdge(3,0,sec).first].label = "m";
    sec[addEdge(4,2,sec).first].label = "m";
    this->s = sec;
    
    Graph_p pro(8);
    pro[0].edgeFst = boost::edge(3,0,fst).first; pro[0].edgeSec = boost::edge(3,0,sec).first;
    pro[1].edgeFst = boost::edge(2,3,fst).first; pro[1].edgeSec = boost::edge(4,2,sec).first;
    pro[2].edgeFst = boost::edge(2,3,fst).first; pro[2].edgeSec = boost::edge(2,3,sec).first;
    pro[3].edgeFst = boost::edge(2,3,fst).first; pro[3].edgeSec = boost::edge(1,2,sec).first;
    pro[4].edgeFst = boost::edge(1,2,fst).first; pro[4].edgeSec = boost::edge(4,2,sec).first;
    pro[5].edgeFst = boost::edge(1,2,fst).first; pro[5].edgeSec = boost::edge(2,3,sec).first;
    pro[6].edgeFst = boost::edge(1,2,fst).first; pro[6].edgeSec = boost::edge(1,2,sec).first;
    pro[7].edgeFst = boost::edge(0,1,fst).first; pro[7].edgeSec = boost::edge(0,1,sec).first;
    pro[addEdge(0,2,pro).first].label = "z";
    pro[addEdge(0,4,pro).first].label = "u";
    pro[addEdge(0,6,pro).first].label = "u";
    pro[addEdge(0,7,pro).first].label = "z";
    pro[addEdge(1,5,pro).first].label = "z";
    pro[addEdge(1,6,pro).first].label = "z";
    pro[addEdge(1,7,pro).first].label = "u";
    pro[addEdge(2,4,pro).first].label = "z";
    pro[addEdge(2,6,pro).first].label = "z";
    pro[addEdge(2,7,pro).first].label = "u";
    pro[addEdge(3,4,pro).first].label = "z";
    pro[addEdge(3,5,pro).first].label = "z";
    pro[addEdge(6,7,pro).first].label = "z";
    this->p = pro;
    
    this->clique = {0,2,4};
}
Exemple #18
0
bool ModelPackager::loadModel() {
    // First we check the FST file (if any)
    if (_modelFile.completeSuffix().contains("fst")) {
        QFile fst(_modelFile.filePath());
        if (!fst.open(QFile::ReadOnly | QFile::Text)) {
            OffscreenUi::asyncWarning(NULL,
                                 QString("ModelPackager::loadModel()"),
                                 QString("Could not open FST file %1").arg(_modelFile.filePath()),
                                 QMessageBox::Ok);
            qWarning() << QString("ModelPackager::loadModel(): Could not open FST file %1").arg(_modelFile.filePath());
            return false;
        }
        qCDebug(interfaceapp) << "Reading FST file";
        _mapping = FSTReader::readMapping(fst.readAll());
        fst.close();
        
        _fbxInfo = QFileInfo(_modelFile.path() + "/" + _mapping.value(FILENAME_FIELD).toString());
    } else {
        _fbxInfo = QFileInfo(_modelFile.filePath());
    }
    
    // open the fbx file
    QFile fbx(_fbxInfo.filePath());
    if (!_fbxInfo.exists() || !_fbxInfo.isFile() || !fbx.open(QIODevice::ReadOnly)) {
        OffscreenUi::asyncWarning(NULL,
                             QString("ModelPackager::loadModel()"),
                             QString("Could not open FBX file %1").arg(_fbxInfo.filePath()),
                             QMessageBox::Ok);
        qWarning() << "ModelPackager::loadModel(): Could not open FBX file";
        return false;
    }
    try {
        qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath();
        QByteArray fbxContents = fbx.readAll();

        _hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath());

        // make sure we have some basic mappings
        populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel);
    } catch (const QString& error) {
        qCDebug(interfaceapp) << "Error reading: " << error;
        return false;
    }
    return true;
}
// address: 0x10744
int main(int argc, char *argv[], char *envp[]) {
    int local0; 		// m[o6 - 24]
    unsigned char *local1; 		// m[o6 - 28]
    int local2; 		// m[o6 - 20]
    int o0; 		// r8

    local0 = 0;
    mid(0x20a50);
    fst(0x20a46);
    local1 = 0x20a50;
    local2 = 0;
    while (local2 <= 4) {
        o0 = *(unsigned char*)local1;
        local0 += (int)(o0 * 0x1000000) >> 24;
        local1++;
        local2++;
    }
    printf("Sum is %d\n", local0);
    return 0;
}
// address: 0x80483ac
int main(int argc, char *argv[], char *envp[]) {
    __size32 edx; 		// r26
    int local0; 		// m[esp - 12]
    char *local2; 		// m[esp - 16]
    int local3; 		// m[esp - 8]

    local0 = 0;
    mid(0x8049654);
    fst(0x804964a);
    local2 = "\x02\x04\x06\b\n";
    local3 = 0;
    while (local3 <= 4) {
        edx = (int) *local2;
        local0 += edx;
        local2++;
        local3++;
    }
    printf("Sum is %d\n", local0);
    return 0;
}
Exemple #21
0
/** address: 0x00010744 */
int main(int argc, char *argv[])
{
    int local0; 		// m[o6 - 24]
    __size32 local1; 		// m[o6 - 28]
    int local2; 		// m[o6 - 20]
    int o0; 		// r8

    local0 = 0;
    mid(0x20a50);
    fst(0x20a46);
    local1 = 0x20a50;
    local2 = 0;
    while (local2 <= 4) {
        o0 = *(unsigned char*)local1;
        local0 += o0 << 24 >> 24;
        local1++;
        local2++;
    }
    printf("Sum is %d\n", local0);
    return 0;
}
Exemple #22
0
/** address: 0x080483ac */
int main(int argc, char *argv[])
{
    int edx; 		// r26
    int local0; 		// m[esp - 12]
    __size32 local2; 		// m[esp - 16]
    int local3; 		// m[esp - 8]

    local0 = 0;
    mid(0x8049654);
    fst(0x804964a);
    local2 = 0x8049654;
    local3 = 0;
    while (local3 <= 4) {
        edx = (int) *local2;
        local0 += edx;
        local2++;
        local3++;
    }
    printf("Sum is %d\n", local0);
    return 0;
}
Exemple #23
0
static int gr_nextinout(lua_State *L, edge_first_iter_t *fst, edge_next_iter_t *nxt)
{
  int rv;
  Agedge_t *e;
  char sbuf[32];
  gr_edge_t *ud_e;
  gr_node_t *ud_n = tonode(L, 1, STRICT);
  Agraph_t *g = agroot(ud_n->n);

  if (lua_isnil(L, 2))
    e = fst(g, ud_n->n);
  else {
    ud_e = toedge(L, 2, STRICT);
    e = nxt(g, ud_e->e);
  }
  if (!e){
    /* no more nodes */
    lua_pushnil(L);
    return 1;
  } else {
    /* Check whether userdata exists .. */
    rv = get_object(L, e);
    if (rv == 1)
      /* .. yes: return it */
      return rv;
    else {
      /* .. no: create it */
      lua_pop(L, rv);
      ud_e = lua_newuserdata(L, sizeof(gr_edge_t)); 
      ud_e->e = e;
      sprintf(sbuf, "edge@%lu", (unsigned long) AGID(e));
      ud_e->name = strdup(sbuf);
      ud_e->type = AGEDGE;
      set_object(L, e);
      return new_edge(L);
    }
  }
}
Exemple #24
0
/* all-in-one function testing epidemics growth, summary statistics, etc. */
void test_epidemics(int seqLength, double mutRate, int npop, int *nHostPerPop, double beta, int nStart, int t1, int t2, int Nsample, int *Tsample, int duration, int *nbnb, int *listnb, double *pdisp){
	int i, j, nstep=0, tabidx, counter_sample = 0;

	/* Initialize random number generator */
	time_t t;
	t = time(NULL); // time in seconds, used to change the seed of the random generator
	gsl_rng * rng;
	const gsl_rng_type *typ;
	gsl_rng_env_setup();
	typ=gsl_rng_default;
	rng=gsl_rng_alloc(typ);
	gsl_rng_set(rng,t); // changes the seed of the random generator


	/* transfer simulation parameters */
	struct param * par;
	par = (struct param *) malloc(sizeof(struct param));
	par->L = seqLength;
	par->mu = mutRate;
	par->muL = par->mu * par->L;
	par->rng = rng;
	par->npop = npop;
	par->npop = npop;
	par->popsizes = nHostPerPop;
	par->beta = beta;
	par->nstart = nStart;
	par->t1 = t1;
	par->t2 = t2;
	par->t_sample = Tsample;
	par->n_sample = Nsample;
	par->duration = duration;
	par->cn_nb_nb = nbnb;
	par->cn_list_nb = listnb;
	par->cn_weights = pdisp;

	/* check/print parameters */
	check_param(par);
	print_param(par);

	/* dispersal matrix */
	struct network *cn = create_network(par);

	/* group sizes */
	struct ts_groupsizes * grpsizes = create_ts_groupsizes(par);


	/* initiate population */
	struct metapopulation * metapop;
	metapop = create_metapopulation(par);


	/* get sampling schemes (timestep+effectives) */
	translate_dates(par);
	struct table_int *tabdates = get_table_int(par->t_sample, par->n_sample);
	printf("\n\nsampling at timesteps:");
	print_table_int(tabdates);

	/* create sample */
	struct sample ** samplist = (struct sample **) malloc(tabdates->n * sizeof(struct sample *));
	struct sample *samp;


	/* MAKE METAPOPULATION EVOLVE */
	nstep = 0;
	while(get_total_nsus(metapop)>0 && (get_total_ninf(metapop)+get_total_nexp(metapop))>0 && nstep<par->duration){
		nstep++;

		/* age metapopulation */
		age_metapopulation(metapop, par);

		/* process infections */
		for(j=0;j<get_npop(metapop);j++){
			process_infections(get_populations(metapop)[j], metapop, cn, par);
		}

		/* draw samples */
		if((tabidx = int_in_vec(nstep, tabdates->items, tabdates->n)) > -1){ /* TRUE if step must be sampled */
			samplist[counter_sample++] = draw_sample(metapop, tabdates->times[tabidx], par);
		}

		fill_ts_groupsizes(grpsizes, metapop, nstep);

	}


	/* we stopped after 'nstep' steps */
	if(nstep < par->duration){
		printf("\nEpidemics ended at time %d, before last sampling time (%d).\n", nstep, par->duration);
	} else {

		printf("\n\n-- FINAL METAPOPULATION --");
		print_metapopulation(metapop, TRUE);

		/* test samples */
		for(i=0;i<tabdates->n;i++) {
			printf("\nsample %d\n", i);
			print_sample(samplist[i], TRUE);
		}
		samp = merge_samples(samplist, tabdates->n, par) ;
		print_sample(samp, TRUE);

		/* test allele listing */
		struct snplist *snpbilan;
		snpbilan = list_snps(samp, par);
		print_snplist(snpbilan);

		/* test allele frequencies */
		struct allfreq *freq;
		freq = get_frequencies(samp, par);
		print_allfreq(freq);

		/* test Hs*/
		double Hs = hs(samp,par);
		printf("\nHs = %0.3f\n", Hs);

		/* test Hs full genome */
		Hs = hs_full_genome(samp,par);
		printf("\nHs (full genome) = %0.5f\n", Hs);

		/* test nb of snps */
		int nball = nb_snps(samp,par);
		printf("\nnumber of SNPs = %d\n", nball);

		/* test mean nb of snps */
		double temp = mean_nb_snps(samp);
		printf("\nmean number of SNPs = %.2f\n", temp);

		/* test var nb of snps */
		temp = var_nb_snps(samp);
		printf("\nvariance of number of alleles = %.2f\n", temp);

		/* test pairwise distances */
		struct distmat_int *mat = pairwise_dist(samp, par);
		print_distmat_int(mat);

		/* test mean pairwise distances */
		temp = mean_pairwise_dist(samp,par);
		printf("\nmean pairwise distance: %.2f", temp);

		/* test variance of pairwise distances */
		temp = var_pairwise_dist(samp,par);
		printf("\nvar pairwise distance: %.2f", temp);

		/* test Fst */
		temp = fst(samp,par);
		printf("\nfst: %.2f", temp);


		printf("\n\n");

		/* free memory */
		free_sample(samp);
		free_snplist(snpbilan);
		free_allfreq(freq);
		free_distmat_int(mat);

	}

	/* write group sizes to file */
	printf("\n\nPrinting group sizes to file 'out-popsize.txt'");
	write_ts_groupsizes(grpsizes);

	/* free memory */
	free_metapopulation(metapop);
	free_param(par);
	for(i=0;i<counter_sample;i++) free_sample(samplist[i]);
	free(samplist);
	free_table_int(tabdates);
	free_network(cn);
	free_ts_groupsizes(grpsizes);
}
Exemple #25
0
int main(int argc,char **argv){
  
  //start of signal handling
  struct sigaction sa;
  sigemptyset (&sa.sa_mask);
  sa.sa_flags = 0;
  sa.sa_handler = handler;
  sigaction(SIGPIPE, &sa, 0);
  sigaction(SIGINT, &sa, 0);  

  if(argc==1){
    //    fprintf(stderr, "\t->------------------\n\t-> ./realSFS\n\t->------------------\n");
    // fprintf(stderr,"\t-> This is the new realSFS program which works on the newer binary files from ANGSD!!\n");
    fprintf(stderr, "\t-> ---./realSFS------\n\t-> EXAMPLES FOR ESTIMATING THE (MULTI) SFS:\n\n\t-> Estimate the SFS for entire genome??\n");
    fprintf(stderr,"\t-> ./realSFS afile.saf.idx \n");
    fprintf(stderr, "\n\t-> 1) Estimate the SFS for entire chromosome 22 ??\n");
    fprintf(stderr,"\t-> ./realSFS afile.saf.idx -r chr22 \n");
    fprintf(stderr, "\n\t-> 2) Estimate the 2d-SFS for entire chromosome 22 ??\n");
    fprintf(stderr,"\t-> ./realSFS afile1.saf.idx  afile2.saf.idx -r chr22 \n");

    fprintf(stderr, "\n\t-> 3) Estimate the SFS for the first 500megabases (this will span multiple chromosomes) ??\n");
    fprintf(stderr,"\t-> ./realSFS afile.saf.idx -nSites 500000000 \n");

    fprintf(stderr, "\n\t-> 4) Estimate the SFS around a gene ??\n");
    fprintf(stderr,"\t-> ./realSFS afile.saf.idx -r chr2:135000000-140000000 \n");
    fprintf(stderr, "\n\t-> Other options [-P nthreads -tole tolerence_for_breaking_EM -maxIter max_nr_iterations -bootstrap number_of_replications]\n");

    fprintf(stderr,"\n\t-> See realSFS print for possible print options\n");
    fprintf(stderr,"\t-> Use realSFS print_header for printing the header\n");

    fprintf(stderr,"\n\t->------------------\n\t-> NB: Output is now counts of sites instead of log probs!!\n");
    fprintf(stderr,"\t-> NB: You can print data with ./realSFS print afile.saf.idx !!\n");
    fprintf(stderr,"\t-> NB: Higher order SFS's can be estimated by simply supplying multiple .saf.idx files!!\n");
    fprintf(stderr,"\t-> NB: Program uses accelerated EM, to use standard EM supply -m 0 \n");
    return 0;
  }
  ++argv;
  --argc;
  if(!strcasecmp(*argv,"print"))
    print<float>(--argc,++argv);
  else if(!strcasecmp(*argv,"cat"))
    saf_cat(--argc,++argv);
  else if(!strcasecmp(*argv,"fst"))
    fst(--argc,++argv);
  else if(!strcasecmp(*argv,"print_header"))
    print_header(--argc,++argv);
  else {
    args *arg = getArgs(argc,argv);
    if(arg->saf.size()>1)
      fprintf(stderr,"\t-> Multi SFS is 'still' under development. Please report strange behaviour\n");
    if(!arg)
      return 0;

    if(isatty(fileno(stdout))){
      fprintf(stderr,"\t-> You are printing the optimized SFS to the terminal consider dumping into a file\n");
      fprintf(stderr,"\t-> E.g.: \'./realSFS");
      for(int i=0;i<argc;i++)
	fprintf(stderr," %s",argv[i]);
      fprintf(stderr," >sfs.ml.txt\'\n");   
    }
  

    main_opt<float>(arg);
    
  }
  if(bootstrap!=NULL)
    delete [] bootstrap;
  return 0;
}
Exemple #26
0
P list_to_array128(P list) {
  return fst(list_to_array128_rec(list, 128));
}
Exemple #27
0
bool FstReader::zip() {
    // File Dialog
    QString filename = QFileDialog::getOpenFileName(NULL,
                                                    "Select your .fst file ...",
                                                    QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
                                                    "*.fst");
    
    // First we check the FST file
    QFile fst(filename);
    if (!fst.open(QFile::ReadOnly | QFile::Text)) {
        qDebug() << "[ERROR] Could not open FST file : " << fst.fileName();
        return false;
    }
    
    // Compress and copy the fst
    if (!compressFile(QFileInfo(fst).filePath(), _zipDir.path() + "/" + QFileInfo(fst).fileName())) {
        return false;
    }
    _totalSize += QFileInfo(fst).size();
    if (!addPart(_zipDir.path() + "/" + QFileInfo(fst).fileName(),
                 QString("fst"))) {
        return false;
    }
    qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
    
    // Let's read through the FST file
    QTextStream stream(&fst);
    QList<QString> line;
    while (!stream.atEnd()) {
        line = stream.readLine().split(QRegExp("[ =]"), QString::SkipEmptyParts);
        if (line.isEmpty()) {
            continue;
        }
        
        if (_totalSize > MAX_SIZE) {
            qDebug() << "[ERROR] Model too big, over " << MAX_SIZE << " Bytes.";
            return false;
        }
        
        // according to what is read, we modify the command
        if (line.first() == NAME_FIELD) {
            QHttpPart textPart;
            textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
                               " name=\"model_name\"");
            textPart.setBody(line[1].toUtf8());
            _dataMultiPart->append(textPart);
        } else if (line.first() == FILENAME_FIELD) {
            QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]);
            if (!fbx.exists() || !fbx.isFile()) { // Check existence
                qDebug() << "[ERROR] FBX file " << fbx.absoluteFilePath() << " doesn't exist.";
                return false;
            }
            // Compress and copy
            if (!compressFile(fbx.filePath(), _zipDir.path() + "/" + line[1])) {
                return false;
            }
            _totalSize += fbx.size();
            if (!addPart(_zipDir.path() + "/" + line[1], "fbx")) {
                return false;
            }
        } else if (line.first() == TEXDIR_FIELD) { // Check existence
            QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]);
            if (!texdir.exists() || !texdir.isDir()) {
                qDebug() << "[ERROR] Texture directory " << texdir.absolutePath() << " doesn't exist.";
                return false;
            }
            if (!addTextures(texdir)) { // Recursive compress and copy
                return false;
            }
        } else if (line.first() == LOD_FIELD) {
            QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]);
            if (!lod.exists() || !lod.isFile()) { // Check existence
                qDebug() << "[ERROR] FBX file " << lod.absoluteFilePath() << " doesn't exist.";
                return false;
            }
            // Compress and copy
            if (!compressFile(lod.filePath(), _zipDir.path() + "/" + line[1])) {
                return false;
            }
            _totalSize += lod.size();
            if (!addPart(_zipDir.path() + "/" + line[1], QString("lod%1").arg(++_lodCount))) {
                return false;
            }
        }
    }
    
    _readyToSend = true;
    return true;
}
Exemple #28
0
bool ModelPackager::zipModel() {
    QTemporaryDir dir;
    dir.setAutoRemove(true);
    QDir tempDir(dir.path());
    
    QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
    tempDir.mkpath(nameField + "/textures");
    tempDir.mkpath(nameField + "/scripts");
    QDir fbxDir(tempDir.path() + "/" + nameField);
    QDir texDir(fbxDir.path() + "/textures");
    QDir scriptDir(fbxDir.path() + "/scripts");

    // Copy textures
    listTextures();
    if (!_textures.empty()) {
        QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
        _texDir = _modelFile.path() + "/" + texdirField;
        copyTextures(_texDir, texDir);
    }

    // Copy scripts
    QByteArray scriptField = _mapping.value(SCRIPT_FIELD).toByteArray();
    _mapping.remove(SCRIPT_FIELD);
    if (scriptField.size() > 1) {
        tempDir.mkpath(nameField + "/scripts");
        _scriptDir = _modelFile.path() + "/" + scriptField;
        QDir wdir = QDir(_scriptDir);
        _mapping.remove(SCRIPT_FIELD);
        wdir.setSorting(QDir::Name | QDir::Reversed);
        auto list = wdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);
        for (auto script : list) {
            auto sc = tempDir.relativeFilePath(scriptDir.path()) + "/" + QUrl(script).fileName();
            _mapping.insertMulti(SCRIPT_FIELD, sc);
        }
        copyDirectoryContent(wdir, scriptDir);
    } 
    
    // Copy LODs
    QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
    if (!lodField.empty()) {
        for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
            QString oldPath = _modelFile.path() + "/" + it.key();
            QFile lod(oldPath);
            QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
            if (lod.exists()) {
                lod.copy(newPath);
            }
        }
    }
    
    // Copy FBX
    QFile fbx(_fbxInfo.filePath());
    QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
    QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
    fbx.copy(newPath);
    
    // Correct FST
    _mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
    _mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());

    for (auto multi : _mapping.values(SCRIPT_FIELD)) {
        multi.fromValue(tempDir.relativeFilePath(scriptDir.path()) + multi.toString());
    }
    // Copy FST
    QFile fst(tempDir.path() + "/" + nameField + ".fst");
    if (fst.open(QIODevice::WriteOnly)) {
        fst.write(FSTReader::writeMapping(_mapping));
        fst.close();
    } else {
        qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
        return false;
    }
    
    
    QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
                                                        "", QFileDialog::ShowDirsOnly);
    if (saveDirPath.isEmpty()) {
        qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
        return false;
    }
    
    QDir saveDir(saveDirPath);
    copyDirectoryContent(tempDir, saveDir);
    return true;
}
Exemple #29
0
// step
P step2(P ai, P game) {
	P map;

	P game2;

	P lambdaman;
	int vitality;
	P lambdaman2;
	P lambdalocation;
	int lambdax;
	int lambday;
	P lambdaman3;
	int lambdadirection;
	P lambdaman4;
	int lambdalive;
	int lambdascore;

	int ghostlength;

	P game3;
	P ghosts;

	P tempghost;
	int ghostvitality;
	P ghostlocation;
	int ghosty;
	int ghostx;
	int ghostdirection;

	int ghostdist;
	int ghostdist2;
	int ghostpoint;

	P fruits;

	int uppoint;
	int rightpoint;
	int downpoint;
	int leftpoint;

	int maxpoint;

	int retdirection;

	int ghostmul;

	int fruittime;

	P farpoint;

	turn = turn + 1;

	uppoint = 0;
	rightpoint = 0;
	downpoint = 0;
	leftpoint = 0;

	maxpoint = 0 - 99999999;
	retdirection = 0;

	map = fst(game);
	gmap = map;

	//list_to_tree(game);

	game2 = snd(game);
	lambdaman = fst(game2);
	game3 = snd(game2);
	ghosts = fst(game3);
	fruits = snd(game3);

	fruitbonus = 0;

	fruittime = toi(fruits);
	if(fruittime > 0){
		fruitbonus = 1000;
	}
	else{}

	//debug(fruittime);

	vitality = toi(fst(lambdaman));
	lambdaman2 = snd(lambdaman);
	lambdalocation = fst(lambdaman2);
	lambdax = toi(fst(lambdalocation));
	lambday = toi(snd(lambdalocation));
	lambdaman3 = snd(lambdaman2);
	lambdadirection = toi(fst(lambdaman3));
	lambdaman4 = snd(lambdaman3);
	lambdalive = toi(fst(lambdaman4));
	lambdascore = toi(snd(lambdaman4));

	uppoint = dfs(lambday - 1, lambdax, 10, 0) * 10;
	rightpoint = dfs(lambday, lambdax + 1, 10, 1) * 10;
	downpoint = dfs(lambday + 1, lambdax, 10, 2) * 10;
	leftpoint = dfs(lambday, lambdax - 1, 10, 3) * 10;

	if(getNumber(lambday - 1,lambdax, map) == 0){
		uppoint = 0 - 99999999;
	}
	else{}
	
	if(getNumber(lambday,lambdax + 1, map) == 0){
		rightpoint = 0 - 99999999;
	}
	else{}
	
	if(getNumber(lambday + 1,lambdax, map) == 0){
		downpoint = 0 - 99999999;
	}
	else{}
	
	if(getNumber(lambday,lambdax - 1, map) == 0){
		leftpoint = 0 - 99999999;
	}
	else{}

	//farpoint = P(0,0);
	//farpoint = getfarpoint(0, 0, map, lambday, lambdax);

	//uppoint = uppoint + toi(fst(farpoint));
	//rightpoint = rightpoint - toi(snd(farpoint));
	//downpoint = downpoint - toi(fst(farpoint));
	//leftpoint = leftpoint + toi(snd(farpoint));

	//ghostlength = 2 + mod(turn / 5, 13);
	ghostlength = 4;

	if(mod(myrand(), 30) == 0){
		randomv = mod(myrand(), 7);
	}

	if(randomv == 0){
		uppoint = uppoint + 1000;
	}
	else{}
	if(randomv == 1){
		rightpoint = rightpoint + 1000;
	}
	else{}
	if(randomv == 2){
		downpoint = downpoint + 1000;
	}
	else{}
	if(randomv == 3){
		leftpoint = leftpoint + 1000;
	}
	else{}


	while(1 - atom(ghosts)){
			tempghost = fst(ghosts);
		ghosts = snd(ghosts);
			ghostvitality = toi(fst(tempghost));
		tempghost = snd(tempghost);
			ghostlocation = fst(tempghost);
			ghostx = toi(fst(ghostlocation));
		ghosty = toi(snd(ghostlocation));
		ghostdirection = toi(snd(tempghost));
	
		ghostdist = abs(lambdax - ghostx) + abs(lambday - ghosty);

		if(ghostdist < (vitality / 127 - 3) * 2){
			if(ghostvitality == 2){
				ghostmul = 0;
			}
			else{
				ghostmul = -1;
			}
		}
		else{
			ghostmul = 1;
		}

		if(ghostdist < ghostlength){
			ghostpoint = 1000000 * ghostlength / pow2(ghostdist) * ghostmul;
		}
		else{
			ghostpoint = 0;
		}
	
		uppoint = uppoint - ghostpoint * sign(lambday - ghosty);
		rightpoint = rightpoint + ghostpoint * sign(lambdax - ghostx);
		downpoint = downpoint + ghostpoint * sign(lambday - ghosty);
		leftpoint = leftpoint - ghostpoint * sign(lambdax - ghostx);
	}

	if(maxpoint < uppoint){
		retdirection = 0;
		maxpoint = uppoint;
	}
	else{}
	if(maxpoint < rightpoint){
		retdirection = 1;
		maxpoint = rightpoint;
	}
	else{}
	if(maxpoint < downpoint){
		retdirection = 2;
		maxpoint = downpoint;
	}
	else{}
	if(maxpoint < leftpoint){
		retdirection = 3;
		maxpoint = leftpoint;
	}
	else{}



	return P(P(retdirection, 0), retdirection);
}
Exemple #30
0
Point::Point(const Point& p){
  fst() = p.fst();
  snd() = p.snd();
}