Ejemplo n.º 1
0
int main(int argc, char *args[]) {
  if (argc < 10) {
    cerr << "Usage: <prog> seedWordsFile graphFile freqFile edgeThresold minFreqThreshold maxFreqThreshold affinityThreshold minConnections minEdges" << endl;
    return -1;
  }
  string seedWordsFile = args[1];
  string graphFile = args[2];
  string freqFile = args[3];
  double edgeThreshold = atof(args[4]);
  double minFreqThreshold = atof(args[5]);
  double maxFreqThreshold = atof(args[6]);
  double affinityThreshold = atof(args[7]);
  int minConnections = atoi(args[8]);
  int minEdges = atoi(args[9]);
  TopicExpander expander(seedWordsFile, graphFile,
      freqFile, edgeThreshold, minFreqThreshold, maxFreqThreshold,
      affinityThreshold, minConnections, minEdges);
  cout << "===================" << endl;
  cout << "Strong Clusters" << endl;
  cout << "===================" << endl;
  expander.printClusters();
  cout << "===================" << endl;
  cout << "Weak Clusters" << endl;
  cout << "===================" << endl;
  expander.printWeakClusters();

  return 0;
}
Ejemplo n.º 2
0
I appender(S *s, I *n, S t, I k) //concatenate t to s
{
  if(expander(s,*n+k+1))R -1; //mm/o - failed
  memcpy(*s+*n,t,k);
  *n += k;
  R 0;
}
Ejemplo n.º 3
0
ssize_t getdelim (S *s, size_t *n, int d, FILE *f){   //target, current capacity, delimiter, file
#if 0 
  // this code is MSVC runtime version specific
  char *q; I w=0;
  if (!s) {errno = EINVAL; goto error;}
  if (f->_cnt <= 0) {
    if (expander(s, 1)) goto error;
    (*s)[0] = '\0'; R *n=-1;
  }
  while ((q = memchr(f->_ptr, d, f->_cnt)) == NULL) {
    if (appender(s, &w, (S) f->_ptr, f->_cnt)) goto error;
    goto done;  /* hit EOF */
  }
  q++;  /* snarf the delimiter, too */
  if (appender(s, &w, (S) f->_ptr, q - f->_ptr)) goto error;
  f->_cnt -= q - f->_ptr; f->_ptr = q;
#endif
  I w=0;
  if (!s) {errno = EINVAL; goto error;}
  for(;;) {
    C c=fgetc(f);
    if (EOF == c) R -1;
    if (appender(s, &w, (S)&c, 1)) goto error;
    if (d==c) break;
  }
  (*s)[w] = '\0'; R *n=w;
  error: R *n=-1;
}
Ejemplo n.º 4
0
void
run_wgm_sssp(warthog::scenario_manager& scenmgr)
{
    warthog::weighted_gridmap map(scenmgr.get_experiment(0)->map().c_str());
	warthog::wgridmap_expansion_policy expander(&map);
	warthog::zero_heuristic heuristic(map.width(), map.height());

	warthog::flexible_astar<
		warthog::zero_heuristic,
	   	warthog::wgridmap_expansion_policy> astar(&heuristic, &expander);
	astar.set_verbose(verbose);

	std::cout << "id\talg\texpd\tgend\ttouched\ttime\tsfile\n";
	for(unsigned int i=0; i < scenmgr.num_experiments(); i++)
	{
		warthog::experiment* exp = scenmgr.get_experiment(i);

		int startid = exp->starty() * exp->mapwidth() + exp->startx();
		astar.get_length(map.to_padded_id(startid), warthog::INF);

		std::cout << i<<"\t" << "sssp_wgm" << "\t" 
		<< astar.get_nodes_expanded() << "\t" 
		<< astar.get_nodes_generated() << "\t"
		<< astar.get_nodes_touched() << "\t"
		<< astar.get_search_time()  << "\t"
		<< scenmgr.last_file_loaded() << std::endl;
	}
	std::cerr << "done. total memory: "<< astar.mem() + scenmgr.mem() << "\n";
}
Ejemplo n.º 5
0
void compute_average_rgb(grs_bitmap *bm, array<fix, 3> &rgb)
{
	rgb = {};
	if (unlikely(!bm->get_bitmap_data()))
		return;
	const uint_fast32_t bm_h = bm->bm_h;
	const uint_fast32_t bm_w = bm->bm_w;
	if (unlikely(!bm_h) || unlikely(!bm_w))
		return;

	const auto process_one = [&rgb](uint8_t color) {
		if (color == TRANSPARENCY_COLOR)
			return;
		auto &t_rgb = gr_palette[color];
		if (t_rgb.r == t_rgb.g && t_rgb.r == t_rgb.b)
			return;
		rgb[0] += t_rgb.r;
		rgb[1] += t_rgb.g;
		rgb[2] += t_rgb.b;
	};
	if (bm->get_flag_mask(BM_FLAG_RLE))
	{
		bm_rle_expand expander(*bm);
		const auto &&buf = make_unique<uint8_t[]>(bm_w);
		for (uint_fast32_t i = 0; i != bm_h; ++i)
		{
			const auto &&range = unchecked_partial_range(buf.get(), bm_w);
			if (expander.step(bm_rle_expand_range(range.begin(), range.end())) != bm_rle_expand::again)
				break;
			range_for (const auto color, range)
				process_one(color);
		}
	}
Ejemplo n.º 6
0
void GraphDrawingScene::expandSceneRect(const QPoint& position)
{
    // start by creating a rectangle around the position that has been passed
    QRect expander(position.x() - 250, position.y() - 250, 500, 500);
    // calculate the bounding rectangle of what we already have and what we wan to add
    setSceneRect(sceneRect().united(expander));
    dynamic_cast<GraphDrawingView*>(parent())->setSceneRect(sceneRect());
}
void QuarterlyIndexFileRetriever::UnzipLocalIndexFile (const fs::path& local_zip_file_name)
{
	std::ifstream zipped_file(local_zip_file_name.string(), std::ios::in | std::ios::binary);
	Poco::Zip::Decompress expander(zipped_file, local_zip_file_name.parent_path().string(), true);

	expander.decompressAllFiles();

}		// -----  end of method QuarterlyIndexFileRetriever::UnzipLocalIndexFile  -----
Ejemplo n.º 8
0
Simulation* SimulationMaker::parse(QString fileName_)
{
    fileName = fileName_;
	QString simName, simVersion;

    XmlExpander expander(fileName, "_expanded");
	emit beginExpansion();
	expander.expand();
	emit endExpansion();	
    fileName = expander.newFileName();
	
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly)) throw Exception(message("Cannot open file: '"+fileName+"' for reading."));
	reader->setDevice(&file);

    if (!nextElementDelim()) throw Exception(message("File is not in valid XML format"));
    if (elementNameNotEquals("simulation")) throw Exception(message("Root element must be 'simulation'"));

    simName = attributeValue("name");
	if (simName.isEmpty()) simName = "anonymous";
    simVersion = attributeValue("version");
	if (simVersion.isEmpty()) simVersion = "1.0";
	
	Simulation *sim = new Simulation(simName, simVersion);
    UniSim::setSimulationObject(sim);

	nextElementDelim();
    int iCon=0, iMod=0, iOut=0;
    while (!reader->hasError() && reader->isStartElement()) {
        if (elementNameEquals("integrator") || elementNameEquals("controller")) {
			if (readIntegratorElement(sim)) ++iCon;
        } else if (elementNameEquals("model")) {
			if (readModelElement(sim)) ++iMod;
        } else if (elementNameEquals("output")) {
			if (readOutputElement(sim)) ++iOut;
		} else {
            throw Exception(message("Unknown element in 'simulation' element: " + elementName()));
		}
	}
	Q_ASSERT(reader->isEndElement());
    if (reader->hasError()) throw Exception(message(""));
    if (iCon==0) throw Exception(message("Missing 'integrator' element in 'simulation'"));
    else if (iCon>1) throw Exception(message("Only one 'integrator' element allowed in 'simulation'"));
    if (iMod==0) throw Exception(message("Missing 'model' element in 'simulation'"));
    if (iOut==0) throw Exception(message("Missing 'output' element in 'simulation'"));

	reader->clear();
    emit beginInitialization();
    sim->initialize(_sequence);
    emit endInitialization();

    return sim;
}
Ejemplo n.º 9
0
Archivo: eval.c Proyecto: kbob/kbscheme
static obj_t *expand(obj_t *expr, env_t *env)
{
    PUSH_ROOT(expr);
    PUSH_ROOT(env);
    AUTO_ROOT(proc, expander());
    AUTO_ROOT(args, make_pair(env, NIL));
    args = make_pair(expr, args);
    //printf_unchecked("proc = %O\n", proc);
    //printf_unchecked("args = %O\n", args);
    FRAME = NIL;
    FRAME = MAKE_CALL(b_eval, make_boolean(false), env);
    apply_procedure(proc, args);
    POP_FUNCTION_ROOTS();
    return eval_frame(FRAME);
}
Ejemplo n.º 10
0
I getdelim(S *s,size_t*n, I d, FILE *f)//target, current capacity, delimiter, file
{
  unsigned char *q;
  I w=0;

  flockfile(f);
  //ORIENT(f,-1)  //is this dangerous?

  if (!s) {errno = EINVAL; goto error;}

  if (f->_r <= 0 && __srefill(f))
  {
    /* If f is at EOF already, we just need space for the NUL. */
    if (__sferror(f) || expander(s, 1)) goto error;
    funlockfile(f);
    (*s)[0] = '\0';
    R *n=-1;
  }

  while ((q = memchr(f->_p, d, f->_r)) == NULL)
  {
    if (appender(s, &w, (S) f->_p, f->_r)) goto error;
    if (__srefill(f))
    {
      if (__sferror(f)) goto error;
      goto done;  /* hit EOF */
    }
  }
  q++;  /* snarf the delimiter, too */
  if (appender(s, &w, (S) f->_p, q - f->_p)) goto error;
  f->_r -= q - f->_p;
  f->_p = q;

  done:
    /* Invariant: *s has space for at least w+1 bytes. */
    (*s)[w] = '\0';
    funlockfile(f);
    R *n=w;

  error:
    f->_flags |= __SERR;
    funlockfile(f);
    R *n=-1;
}
Ejemplo n.º 11
0
std::vector<Component> associate(cv::Mat const &depth_map, int threshold)
{
    Expander expander(depth_map.rows, depth_map.cols);
    cv::Mat mask = cv::Mat::zeros(depth_map.rows, depth_map.cols, cv::DataType<bool>::type);
    std::vector<Component> components;
    for(int i = 0; i < depth_map.rows; i++)
    {
        for(int j = 0; j < depth_map.cols; j++)
        {
            if (mask.data[i*depth_map.cols + j] == 0)
            {
                mask.data[i*depth_map.cols + j] = 1;
                Component tmp = searchComponent(Point(i, j), depth_map, mask, expander, threshold);
                if (tmp.points.size() > 5) components.push_back(tmp);
            }
        }
    }
    return components;
}
Ejemplo n.º 12
0
void
run_jps_wgm(warthog::scenario_manager& scenmgr)
{
    warthog::weighted_gridmap map(scenmgr.get_experiment(0)->map().c_str());
	warthog::jps_expansion_policy_wgm expander(&map);
	warthog::octile_heuristic heuristic(map.width(), map.height());

	warthog::flexible_astar<
		warthog::octile_heuristic,
	   	warthog::jps_expansion_policy_wgm> astar(&heuristic, &expander);
	astar.set_verbose(verbose);
    // cheapest terrain (movingai benchmarks) has ascii value '.'; we scale
    // all heuristic values accordingly (otherwise the heuristic doesn't 
    // impact f-values much and search starts to behave like dijkstra)
    astar.set_hscale('.');  

	std::cout << "id\talg\texpd\tgend\ttouched\ttime\tcost\tsfile\n";
	for(unsigned int i=0; i < scenmgr.num_experiments(); i++)
	{
		warthog::experiment* exp = scenmgr.get_experiment(i);

		int startid = exp->starty() * exp->mapwidth() + exp->startx();
		int goalid = exp->goaly() * exp->mapwidth() + exp->goalx();
		double len = astar.get_length(
				map.to_padded_id(startid),
			   	map.to_padded_id(goalid));
		if(len == warthog::INF)
		{
			len = 0;
		}

		std::cout << i<<"\t" << "jps_wgm" << "\t" 
		<< astar.get_nodes_expanded() << "\t" 
		<< astar.get_nodes_generated() << "\t"
		<< astar.get_nodes_touched() << "\t"
		<< astar.get_search_time()  << "\t"
		<< len << "\t" 
		<< scenmgr.last_file_loaded() << std::endl;

		check_optimality(len, exp);
	}
	std::cerr << "done. total memory: "<< astar.mem() + scenmgr.mem() << "\n";
}
Ejemplo n.º 13
0
int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory,
                           expand_flags_t flags, std::vector<completion_t> *output) {
    assert(output != NULL);
    // Fuzzy matching only if we're doing completions.
    assert(flags.get(expand_flag::for_completions) || !flags.get(expand_flag::fuzzy_match));

    // expand_flag::special_for_cd requires expand_flag::directories_only and
    // expand_flag::for_completions and expand_flag::no_descriptions.
    assert(!(flags.get(expand_flag::special_for_cd)) ||
           ((flags.get(expand_flag::directories_only)) &&
            (flags.get(expand_flag::for_completions)) &&
            (flags.get(expand_flag::no_descriptions))));

    // Hackish fix for issue #1631. We are about to call c_str(), which will produce a string
    // truncated at any embedded nulls. We could fix this by passing around the size, etc. However
    // embedded nulls are never allowed in a filename, so we just check for them and return 0 (no
    // matches) if there is an embedded null.
    if (wc.find(L'\0') != wcstring::npos) {
        return 0;
    }

    // Compute the prefix and base dir. The prefix is what we prepend for filesystem operations
    // (i.e. the working directory), the base_dir is the part of the wildcard consumed thus far,
    // which we also have to append. The difference is that the base_dir is returned as part of the
    // expansion, and the prefix is not.
    //
    // Check for a leading slash. If we find one, we have an absolute path: the prefix is empty, the
    // base dir is /, and the wildcard is the remainder. If we don't find one, the prefix is the
    // working directory, the base dir is empty.
    wcstring prefix = L"", base_dir = L"", effective_wc;
    if (string_prefixes_string(L"/", wc)) {
        base_dir = L"/";
        effective_wc = wc.substr(1);
    } else {
        prefix = working_directory;
        effective_wc = wc;
    }

    wildcard_expander_t expander(prefix, flags, output);
    expander.expand(base_dir, effective_wc.c_str(), base_dir);
    return expander.status_code();
}
Ejemplo n.º 14
0
void
run_astar(warthog::scenario_manager& scenmgr)
{
    warthog::gridmap map(scenmgr.get_experiment(0)->map().c_str());
	warthog::gridmap_expansion_policy expander(&map);
	warthog::octile_heuristic heuristic(map.width(), map.height());

	warthog::flexible_astar<
		warthog::octile_heuristic,
	   	warthog::gridmap_expansion_policy> astar(&heuristic, &expander);
	astar.set_verbose(verbose);


	std::cout << "id\talg\texpd\tgend\ttouched\ttime\tcost\tsfile\n";
	for(unsigned int i=0; i < scenmgr.num_experiments(); i++)
	{
		warthog::experiment* exp = scenmgr.get_experiment(i);

		int startid = exp->starty() * exp->mapwidth() + exp->startx();
		int goalid = exp->goaly() * exp->mapwidth() + exp->goalx();
		double len = astar.get_length(
				map.to_padded_id(startid), 
				map.to_padded_id(goalid));
		if(len == warthog::INF)
		{
			len = 0;
		}

		std::cout << i<<"\t" << "astar" << "\t" 
		<< astar.get_nodes_expanded() << "\t" 
		<< astar.get_nodes_generated() << "\t"
		<< astar.get_nodes_touched() << "\t"
		<< astar.get_search_time()  << "\t"
		<< len << "\t" 
		<< scenmgr.last_file_loaded() << std::endl;

		check_optimality(len, exp);
	}
	std::cerr << "done. total memory: "<< astar.mem() + scenmgr.mem() << "\n";
}
Ejemplo n.º 15
0
bool ThreadSynth::Synth() {
  tab_ = new ITable(mod_);
  tab_->SetName(thread_name_);
  resource_.reset(new ResourceSet(tab_));
  RequestMethod(method_name_);
  int num_synth;
  do {
    num_synth = 0;
    for (auto it : methods_) {
      if (it.second != nullptr) {
	continue;
      }
      num_synth++;
      MethodSynth *m =
	new MethodSynth(this, it.first, tab_, resource_.get());
      if (!m->Synth()) {
	Status::os(Status::USER) << "Failed to synthesize thread: "
				 << thread_name_ << "." << method_name_;
	MessageFlush::Get(Status::USER);
	return false;
      }
      methods_[it.first] = m;
      break;
    }
  } while (num_synth > 0);

  MethodSynth *root_method = methods_[method_name_];
  MethodExpander expander(root_method->GetContext(), this, &sub_obj_calls_);
  expander.Expand();
  if (is_task_) {
    root_method->InjectTaskEntry(tab_->GetInitialState());
  }

  mod_->tables_.push_back(tab_);
  return true;
}
Ejemplo n.º 16
0
Archivo: main.cpp Proyecto: CCJY/coliru
 void operator()(std::ostream& os, Array const& ctx, mustache::section const& v) const {
     for(auto& item : ctx)
         expander()(os, item, v.content);
 }
Ejemplo n.º 17
0
bool ExpandCallNode::Expand(opSymbolTracker& tracker, opNode::iterator expandit, opNode* parent)
{
	//TODO: reimplement expansion depth checking
	OPERATIONS_START;

	//TODO: add good errors

	//need to have the arguments parsed
	if(Arguments)
		Arguments->PreProcess();
	
	opString signature = GetSignature();
	
	if (OPMacroNode* macro = tracker.OPMacroRegistered(signature))
	{			
		stacked<OPMacroBodyNode> cloned     = macro->GetBody()->Clone();
		opNode*			         parentNode = GetParent();

		++ExpansionDepth;

		if (ExpansionDepth > opParameters::Get().OPMacroExpansionDepth.GetValue())
		{
			opString error = 
				"Maximum opmacro expansion depth (" + 
				opString(opParameters::Get().OPMacroExpansionDepth.GetValue()) + 
				") exceeded!";

			opError::MessageError(this,error);
		}

		// parse arguments
		//NOTE: this in effect finds expands and expands the arguments
		//      before we substitute them into the opmacro

		if (Arguments)
		{
			opMacroExpander expander(tracker,Arguments);

			if(expander.Errored())
				opException::ThrowException();
		}
		
		// expand the cloned nodes
		// this performs the expansion and replacement operations...
		macro->Expand(*cloned, Arguments);
		
		//in order to expand arguments which are ... expand
		//we must determine what order to use for this.
		
		//A. expand within the expand argument (this makes some sort of sense) - I think this is best.
		//how?
		//1. find expands within argument
		//2. run pre-process on this early
		MacroConcatenationWalker operations;

		//perform initial opmacro/concat fixes
		operations.MacroConcatenations(*cloned);

		// identify opmacro and expansion calls
		cloned->FindOPMacros();

		//perform expand/concat fixes
		operations.ExpandConcatenations(*cloned);

		//find expand calls recursively using a walker class
		ExpandFinder expandfind(*cloned);

		//run expand calls recursively
		opMacroExpander expander(tracker,*cloned);
		
		if(expander.Errored())
			opException::ThrowException();
	
		parent->CollapseNode(cloned, expandit);
		
		ExpansionDepth--;
	}
	else
	{
		//TODO: this could be much improved
		opError::ExpandError(this,signature,tracker);
	}

	OPERATIONS_END;
}
Ejemplo n.º 18
0
bool MacroExpander::collectMacroArgs(const Macro &macro,
                                     const Token &identifier,
                                     std::vector<MacroArg> *args,
                                     SourceLocation *closingParenthesisLocation)
{
    Token token;
    getToken(&token);
    assert(token.type == '(');

    args->push_back(MacroArg());
    for (int openParens = 1; openParens != 0; )
    {
        getToken(&token);

        if (token.type == Token::LAST)
        {
            mDiagnostics->report(Diagnostics::PP_MACRO_UNTERMINATED_INVOCATION,
                                 identifier.location, identifier.text);
            // Do not lose EOF token.
            ungetToken(token);
            return false;
        }

        bool isArg = false; // True if token is part of the current argument.
        switch (token.type)
        {
          case '(':
            ++openParens;
            isArg = true;
            break;
          case ')':
            --openParens;
            isArg = openParens != 0;
            *closingParenthesisLocation = token.location;
            break;
          case ',':
            // The individual arguments are separated by comma tokens, but
            // the comma tokens between matching inner parentheses do not
            // seperate arguments.
            if (openParens == 1)
                args->push_back(MacroArg());
            isArg = openParens != 1;
            break;
          default:
            isArg = true;
            break;
        }
        if (isArg)
        {
            MacroArg &arg = args->back();
            // Initial whitespace is not part of the argument.
            if (arg.empty())
                token.setHasLeadingSpace(false);
            arg.push_back(token);
        }
    }

    const Macro::Parameters &params = macro.parameters;
    // If there is only one empty argument, it is equivalent to no argument.
    if (params.empty() && (args->size() == 1) && args->front().empty())
    {
        args->clear();
    }
    // Validate the number of arguments.
    if (args->size() != params.size())
    {
        Diagnostics::ID id = args->size() < macro.parameters.size() ?
            Diagnostics::PP_MACRO_TOO_FEW_ARGS :
            Diagnostics::PP_MACRO_TOO_MANY_ARGS;
        mDiagnostics->report(id, identifier.location, identifier.text);
        return false;
    }

    // Pre-expand each argument before substitution.
    // This step expands each argument individually before they are
    // inserted into the macro body.
    for (std::size_t i = 0; i < args->size(); ++i)
    {
        MacroArg &arg = args->at(i);
        TokenLexer lexer(&arg);
        MacroExpander expander(&lexer, mMacroSet, mDiagnostics, mParseDefined);

        arg.clear();
        expander.lex(&token);
        while (token.type != Token::LAST)
        {
            arg.push_back(token);
            expander.lex(&token);
        }
    }
    return true;
}
Ejemplo n.º 19
0
Mod::Mod(tl::FsNode& root) {
	
	auto sprite_dir = root / "sprites"_S;
	auto sound_dir = root / "sounds"_S;

	this->large_sprites = read_full_tga((sprite_dir / "large.tga"_S).try_get_source(), &this->pal);
	this->small_sprites = read_full_tga((sprite_dir / "small.tga"_S).try_get_source());
	this->small_font_sprites = read_full_tga((sprite_dir / "text.tga"_S).try_get_source());
	//this->font_sprites = read_full_tga((sprite_dir / "font.tga"_S).try_get_source(), &this->pal);

	tl::Palette dummyPal;
	tl::read_tga((sprite_dir / "font.tga"_S).try_get_source(), this->font_sprites, dummyPal);
	

	worm_sprites[0] = tl::Image(16, 7 * 3 * 16, 4);
	worm_sprites[1] = tl::Image(16, 7 * 3 * 16, 4);
	muzzle_fire_sprites[0] = tl::Image(16, 7 * 16, 4);
	muzzle_fire_sprites[1] = tl::Image(16, 7 * 16, 4);

	auto worms = large_sprites.crop(tl::RectU(0, 16 * 16, 16, 16 * (16 + 7 * 3)));
	worm_sprites[0].blit(worms);
	worm_sprites[1].blit(worms, 0, 0, 0, tl::ImageSlice::Flip);

	auto muzzle_fire = large_sprites.crop(tl::RectU(0, 16 * 9, 16, 16 * (9 + 7)));
	muzzle_fire_sprites[0].blit(muzzle_fire);
	muzzle_fire_sprites[1].blit(muzzle_fire, 0, 0, 0, tl::ImageSlice::Flip);

	{
		for (u32 y = 0; y < this->large_sprites.height(); ++y) {
			LargeSpriteRow row = {0, 0};
			for (u32 x = 0; x < 16; ++x) {
				auto p = tl::Color(this->large_sprites.unsafe_pixel32(x, y));
				bool draw = p.a() > 0;
				bool half = p.a() == 1 || p.a() == 2;

				bool bit0 = draw;
				bool bit1 = !(!draw || half);
								
				row.bit0 |= bit0 << x;
				row.bit1 |= bit1 << x;
			}

			this->large_sprites_bits.push_back(row);
		}
	}

	auto r = (root / "tc.dat"_S);

	auto src = r.try_get_source();
	auto buf = src.read_all();

	ss::Expander expander(buf);

	//auto* tc = expander.expand_root<TcData>(*(ss::StructOffset<TcDataReader> const*)buf.begin());
	auto* tc = (liero::TcData *)expander.expand(liero::TcData::expand_program(), buf.begin());

	this->tcdata = tc;
	this->weapon_types = tc->weapons().begin();
	this->level_effects = tc->level_effects().begin();
	this->nobject_types = tc->nobjects().begin();
	this->sobject_types = tc->sobjects().begin();

	for (auto& sound_name : tc->sound_names()) {
		tl::Vec<i16> sound_data;
		read_wav((sound_dir / sound_name.get()).try_get_source(), sound_data);

		this->sounds.push_back(move(sound_data));
	}

	this->mod_data = expander.to_buffer();
}
Ejemplo n.º 20
0
Builder::Builder(Environment* env) :
    env_(env),
    errors_(0) {

    // Initialize default includes to be used if the user-defined includes
    // do not point to the Jogo standard libraries.
    env->include(".");
#ifndef WINDOWS
    env->lib("m");
    env->include("/usr/local/lib");
    env->include("/usr/local/include/jogo");
#else
    env->lib("kernel32");
    env->lib("ws2_32");
    env->lib("mswsock");
    env->lib("wsock32");
    char const* pathstr = getenv("PATH");
    std::string path = pathstr ? pathstr : "";
    std::string const vshome = "C:\\Program Files (x86)\\Microsoft Visual Studio ";
    std::vector<std::string> vcvarsall;
    vcvarsall.push_back("12.0\\VC\\bin\\x86_amd64\\vcvarsx86_amd64.bat");
    vcvarsall.push_back("11.0\\VC\\bin\\amd64\\vcvars64.bat");
    vcvarsall.push_back("11.0\\VC\\bin\\x86_amd64\\vcvarsx86_amd64.bat");
    vcvarsall.push_back("11.0\\VC\\bin\\amd64\\vcvars64.bat");
    vcvarsall.push_back("11.0\\VC\\bin\\x86_amd64\\vcvarsx86_amd64.bat");
    vcvarsall.push_back("10.0\\VC\\bin\\amd64\\vcvars64.bat");
    vcvarsall.push_back("10.0\\VC\\bin\\x86_amd64\\vcvarsx86_amd64.bat");
    for (size_t i = 0; i < vcvarsall.size(); ++i) {
        if(File::is_reg(vshome+vcvarsall[i])) {
            vcvarsall_ = File::base_name(vshome+vcvarsall[i]);
            path += ";"+File::dir_name(vshome+vcvarsall[i]);
            break;
        }
    }
    SetEnvironmentVariable("PATH", path.c_str());
    if(vcvarsall_.empty()) {
        std::cerr << "Valid compiler configuration not found:" << std::endl;
        for (size_t i = 0; i < vcvarsall.size(); ++i) {
            std::cerr << "    no file '" << vshome+vcvarsall[i] << "'" << std::endl;
        }
        exit(1);
    }
    
    // Find a valid 64-bit MSVC compiler configuration

    std::string program_files = getenv("PROGRAMFILES");
    std::string program_files_x86 = getenv("PROGRAMFILES(x86)");
    env->include(program_files + "\\Jogo\\lib");
    env->include(program_files_x86 + "\\Jogo\\lib");
    env->include(program_files + "\\Jogo\\include\\jogo");
    env->include(program_files_x86 + "\\Jogo\\include\\jogo");
#endif
    process_path();

    // Run the compiler.  Output to a temporary file if the compiler will
    // continue on to another stage; otherwise,  the file directly.
    Parser::Ptr parser(new Parser(env));
    if (env_->errors()) {
        errors_++;
    }
    if (env_->dump_lex()) {
        return;
    }
	
    // Semantic analysis/type checking phase.
	if (!env_->errors()) {
		SemanticAnalyzer::Ptr checker(new SemanticAnalyzer(env));
        // Code expansion
        if (!env_->errors()) {
            CodeExpander::Ptr expander(new CodeExpander(env, checker));
        }
	}

    if (env->dump_ast()) {
        TreePrinter::Ptr tprint(new TreePrinter(env, Stream::stout()));
        return;
    }
    if (env_->errors()) {
        errors_++;
        return;
    }

    // Final output generatation and linking phase.
    if (env_->monolithic_build()) {
        monolithic_build();
    } else {
        modular_build();
    }
}
Ejemplo n.º 21
0
//Add this input and output to the GP
void SOGP::add(const ColumnVector& in,const ColumnVector& out){
  double kstar =m_params.m_kernel->kstar(in);
  
  if(current_size==0){//First point is easy
    C.ReSize(1,1);
    Q.ReSize(1,1);
    //Equations 2.46 with q, r, and s collapsed
    alpha=out.t()/(kstar+m_params.s20);
    C(1,1)=-1/(kstar+m_params.s20);
    Q(1,1)=1/kstar;
    
    current_size=1;
    BV = in;
  }
  else{   //We already have data
    //perform the kernel
    ColumnVector k=m_params.m_kernel->kernelM(in,BV);

    RowVector m=k.t()*alpha;
    double s2 = kstar+(k.t()*C*k).AsScalar();
    
    if(s2<1e-12){//For numerical stability..from Csato's Matlab code?
      //printf("SOGP::Small s2 %lf\n",s2);
      s2=1e-12;
    }
    
    //Update scalars
    //page 33 - Assumes Gaussian noise
    double r = -1/(m_params.s20+s2);
    //printf("out %d m %d r %f\n",out.Nrows(),m.Ncols(),r);
    RowVector q = -r*(out.t()-m);

    //projection onto current BV
    ColumnVector ehat = Q*k;//Appendix G, section c
    //residual length
    double gamma = kstar-(k.t()*ehat).AsScalar();//Ibid
    if(gamma<1e-12){//Numerical instability?
      //printf("SOGP::Gamma (%lf) < 0\n",gamma);
      gamma=0;
    }

    if(gamma<1e-6 && m_params.capacity!= -1){//Nearly singular, do a sparse update (e_tol)
      //printf("SOGP::Sparse! %lf \n",gamma);
      double eta = 1/(1+gamma*r);//Ibid
      ColumnVector shat = C*k+ehat;//Appendix G section e
      alpha=alpha+shat*(q*eta);//Appendix G section f
      C=C+r*eta*shat*shat.t();//Ibid
    }
    else{//Full update
      //printf("SOGP::Full!\n");
      //Expansions are messy
      RowVector expander(1);

      //s is of length N+1
      expander(1)=1;
      ColumnVector s = C*k & expander;//Apendix G section e

      //Add a row to alpha
      expander.ReSize(alpha.Ncols());
      for(int i=0;i<alpha.Ncols();i++)
	expander(i+1)=0;
      alpha = alpha & expander;
      //Update alpha
      alpha=alpha+s*q;//Equations 2.46

      //Add Row to C
      expander.ReSize(C.Ncols());
      for(int i=0;i<C.Ncols();i++)
	expander(i+1)=0;
      C = C&expander;
      //Add a Column to C
      expander.ReSize(C.Nrows());
      for(int i=0;i<C.Nrows();i++)
	expander(i+1)=0;
      C = C | expander.t();
      //Update C
      C = C + r*s*s.t();//Ibid

      //Save the data, N++
      BV = BV | in;
      current_size++;
  
      //Add row to Gram Matrix
      expander.ReSize(Q.Ncols());
      for(int i=0;i<Q.Ncols();i++)
	expander(i+1)=0;
      Q = Q&expander;
      //Add column
      expander.ReSize(Q.Nrows());
      for(int i=0;i<Q.Nrows();i++)
	expander(i+1)=0;
      Q = Q | expander.t();
      //Add one more to ehat
      expander.ReSize(1);
      expander(1)=-1;
      ehat = ehat & expander;
      //Update gram matrix
      Q = Q + (1/gamma)*ehat*ehat.t();//Equation 3.5
    }

    //Delete BVs if necessay...maybe only 2 per iteration?
    while(current_size > m_params.capacity && m_params.capacity>0){//We're too big!
      double minscore=0,score;
      int minloc=-1;
      //Find the minimum score
      for(int i=1;i<=current_size;i++){
	score = alpha.Row(i).SumSquare()/(Q(i,i)+C(i,i));
	if(i==1 || score<minscore){
	  minscore=score;
	  minloc=i;
	}
      }
      //Delete it
      delete_bv(minloc);
    }
    
    //Delete for geometric reasons - Loop?
    double minscore=0,score;
    int minloc=-1;
    for(int i=1;i<=current_size;i++){
      score = 1/Q(i,i);
      if(i==1 || score<minscore){
	minscore=score;
	minloc=i;
      }
    }
    if(minscore<1e-9){
      delete_bv(minloc);
    }
  }
}
Ejemplo n.º 22
0
void OpenSMTContext::staticCheckSAT( ) 
{
  if ( config.verbosity > 1 )
    cerr << "# OpenSMTContext::Statically Checking" << endl;

  // Retrieve the formula
  Enode * formula = egraph.getUncheckedAssertions( );

  if ( config.dump_formula != 0 )
    egraph.dumpToFile( "original.smt2", formula );

  if ( formula == NULL )
    opensmt_error( "formula undefined" );

  if ( config.logic == UNDEF )
    opensmt_error( "unable to determine logic" );

  // Removes ITEs if there is any
  if ( egraph.hasItes( ) )
  {
    ExpandITEs expander( egraph, config );
    formula = expander.doit( formula );

    if ( config.dump_formula != 0 )
      egraph.dumpToFile( "ite_expanded.smt2", formula );
  }

  // Gather interface terms for DTC
  if ( ( config.logic == QF_UFIDL
      || config.logic == QF_UFLRA )
    // Don't use with DTC of course
    && config.sat_lazy_dtc == 1
    // Don't use when dumping interpolants
    && config.sat_dump_rnd_inter == 0 )
  {
    Purify purifier( egraph, config );
    purifier.doit( formula );
  }

  // Ackermanize away functional symbols
  if ( ( config.logic == QF_UFIDL
      || config.logic == QF_UFLRA )
    // Don't use with DTC of course
    && config.sat_lazy_dtc == 0
    // Don't use when dumping interpolants
    && config.sat_dump_rnd_inter == 0 )
  {
    Ackermanize ackermanizer( egraph, config );
    formula = ackermanizer.doit( formula );

    if ( config.dump_formula != 0 )
      egraph.dumpToFile( "ackermanized.smt2", formula );
  }

  // Artificially create a boolean
  // abstraction, if necessary
  if ( config.logic == QF_BV )
  {
    BVBooleanize booleanizer( egraph, config );
    formula = booleanizer.doit( formula );
  }

  if ( config.dump_formula != 0 )
    egraph.dumpToFile( "prepropagated.smt2", formula );

  // Top-Level Propagator. It also canonize atoms
  TopLevelProp propagator( egraph, config );
  // Only if sat_dump_rnd_inter is not set
  if ( config.sat_dump_rnd_inter == 0 )
    formula = propagator.doit( formula );

  if ( config.dump_formula != 0 )
    egraph.dumpToFile( "propagated.smt2", formula );

  AXDiffPreproc2 axdiffpreproc( egraph, sstore, config );
  if ( config.logic == QF_AX
    || config.logic == QF_AXDIFF )
  {
    formula = axdiffpreproc.doit( formula );
    if ( config.dump_formula != 0 )
      egraph.dumpToFile( "axdiffpreproc.smt2", formula );
  }

  // Convert RDL into IDL, also compute if GMP is needed
  if ( config.logic == QF_RDL )
  {
    DLRescale rescaler( egraph, config );
    rescaler.doit( formula );
  }

  // For static checking, make sure that if DTC is used
  // then incrementality is enabled
  if ( ( config.logic == QF_UFIDL
      || config.logic == QF_UFLRA )
      && config.sat_lazy_dtc != 0 )
  {
    config.incremental = 1;
    config.sat_polarity_mode = 4;
  }

  if ( config.dump_formula != 0 )
    egraph.dumpToFile( "presolve.smt2", formula );

  // Solve only if not simplified already
  if ( formula->isTrue( ) )
  {
    state = l_True;
  }
  else if ( formula->isFalse( ) )
  {
    state = l_False;
  }
  else
  {
    assert(egraph.isInitialized());
    // Initialize theory solvers
    // egraph.initializeTheorySolvers( &solver );

    // Compute polarities
    egraph.computePolarities( formula );

    // CNFize the input formula and feed clauses to the solver
    state = cnfizer.cnfizeAndGiveToSolver( formula );

    // Solve
    if ( state == l_Undef )
    {
      state = solver.smtSolve( config.sat_preprocess_booleans != 0
                            || config.sat_preprocess_theory   != 0 );
    }

    // If computation has been stopped, return undef
    if ( opensmt::stop ) state = l_Undef;
  }
}
Ejemplo n.º 23
0
bool MacroExpander::collectMacroArgs(const Macro &macro,
                                     const Token &identifier,
                                     std::vector<MacroArg> *args,
                                     SourceLocation *closingParenthesisLocation)
{
    Token token;
    getToken(&token);
    ASSERT(token.type == '(');

    args->push_back(MacroArg());

    // Defer reenabling macros until args collection is finished to avoid the possibility of
    // infinite recursion. Otherwise infinite recursion might happen when expanding the args after
    // macros have been popped from the context stack when parsing the args.
    ScopedMacroReenabler deferReenablingMacros(this);

    int openParens = 1;
    while (openParens != 0)
    {
        getToken(&token);

        if (token.type == Token::LAST)
        {
            mDiagnostics->report(Diagnostics::PP_MACRO_UNTERMINATED_INVOCATION, identifier.location,
                                 identifier.text);
            // Do not lose EOF token.
            ungetToken(token);
            return false;
        }

        bool isArg = false;  // True if token is part of the current argument.
        switch (token.type)
        {
            case '(':
                ++openParens;
                isArg = true;
                break;
            case ')':
                --openParens;
                isArg                       = openParens != 0;
                *closingParenthesisLocation = token.location;
                break;
            case ',':
                // The individual arguments are separated by comma tokens, but
                // the comma tokens between matching inner parentheses do not
                // seperate arguments.
                if (openParens == 1)
                    args->push_back(MacroArg());
                isArg = openParens != 1;
                break;
            default:
                isArg = true;
                break;
        }
        if (isArg)
        {
            MacroArg &arg = args->back();
            // Initial whitespace is not part of the argument.
            if (arg.empty())
                token.setHasLeadingSpace(false);
            arg.push_back(token);
        }
    }

    const Macro::Parameters &params = macro.parameters;
    // If there is only one empty argument, it is equivalent to no argument.
    if (params.empty() && (args->size() == 1) && args->front().empty())
    {
        args->clear();
    }
    // Validate the number of arguments.
    if (args->size() != params.size())
    {
        Diagnostics::ID id = args->size() < macro.parameters.size()
                                 ? Diagnostics::PP_MACRO_TOO_FEW_ARGS
                                 : Diagnostics::PP_MACRO_TOO_MANY_ARGS;
        mDiagnostics->report(id, identifier.location, identifier.text);
        return false;
    }

    // Pre-expand each argument before substitution.
    // This step expands each argument individually before they are
    // inserted into the macro body.
    size_t numTokens = 0;
    for (auto &arg : *args)
    {
        TokenLexer lexer(&arg);
        if (mAllowedMacroExpansionDepth < 1)
        {
            mDiagnostics->report(Diagnostics::PP_MACRO_INVOCATION_CHAIN_TOO_DEEP, token.location,
                                 token.text);
            return false;
        }
        MacroExpander expander(&lexer, mMacroSet, mDiagnostics, mAllowedMacroExpansionDepth - 1);

        arg.clear();
        expander.lex(&token);
        while (token.type != Token::LAST)
        {
            arg.push_back(token);
            expander.lex(&token);
            numTokens++;
            if (numTokens + mTotalTokensInContexts > kMaxContextTokens)
            {
                mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token.location, token.text);
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 24
0
void OpenSMTContext::staticCheckSATInterp( ) 
{
  assert( config.produce_inter != 0 );

  // From now on coloring for new enodes
  // is automatically computed based on
  // the colors of the arguments. Unless
  // forced otherwise ...
  egraph.setAutomaticColoring( );
  // Propagate ABcommon terms if
  // tagged as Alocal/Blocal
  egraph.maximizeColors( );
  
  if ( config.verbosity > 1 )
    cerr << "# OpenSMTContext::Statically Checking" << endl;

  if ( config.logic == UNDEF )
    opensmt_error( "unable to determine logic" );

  if ( config.logic == QF_UFIDL 
    || config.logic == QF_UFLRA )
  {
    if ( config.sat_lazy_dtc == 0 )
      opensmt_warning( "Overriding option sat_lazy_dtc" );
    config.sat_lazy_dtc = 1;
    config.incremental = 1;
    config.sat_polarity_mode = 4;
  }

  // Gather partitions
  vector< Enode * > assertions;
  for ( ;; )
  {
    // Get partition
    Enode * formula = egraph.getNextAssertion( );
    if ( formula == NULL ) break;
    assertions.push_back( formula );
  }

  // Purifier for DTC
  if ( config.logic == QF_UFIDL
    || config.logic == QF_UFLRA )
  {
    Purify purifier( egraph, config );
    purifier.doit( assertions );
  }

  // Ite expander
  ExpandITEs expander( egraph, config );
  
  // Top-Level Propagator. It also canonize atoms
  TopLevelProp propagator( egraph, config );

  // Initialize theory solvers
  egraph.initializeTheorySolvers( &solver );

  // Initialize AXDIFF preprocessor
  AXDiffPreproc axdiffpreproc( egraph, sstore, config );

  for ( size_t in = 0 ; in < assertions.size( ) ; in ++ )
  {
    // Get formula
    Enode * formula = assertions[ in ];
    // const ipartitions_t partition = SETBIT( in + 1 );
    ipartitions_t partition = 0;
    setbit( partition, in + 1 );
    assert( in != 0 || formula != NULL );
    // Remove ites 
    formula = expander.doit( formula );
    // Canonize atoms
    formula = propagator.doit( formula );
    // Preprocessing for AX 
    if ( config.logic == QF_AX
      || config.logic == QF_AXDIFF )
    {
      formula = axdiffpreproc.doit( formula, partition );
    }
    // Some predicates may have been introduced
    // by the last steps. Color them if they are
    // not colored already
    egraph.finalizeColors( formula, partition );

    if ( config.dump_formula != 0 )
    {
      char buf[ 32 ];
      sprintf( buf, "presolve_%ld.smt2", in + 1 );
      egraph.dumpToFile( buf, formula );
    }
    // Restore
    assertions[ in ] = formula;
  }
  //
  // Now give to solver
  //
  for ( size_t in = 0 ; in < assertions.size( ) ; in ++ )
  {
    // const ipartitions_t partition = SETBIT( in + 1 );
    ipartitions_t partition = 0;
    setbit( partition, in + 1 );
    // Get partition
    Enode * formula = assertions[ in ];
    // CNFize the input formula and feed clauses to the solver
    state = cnfizer.cnfizeAndGiveToSolver( formula, partition );
  }

  // Solve
  if ( state == l_Undef )
  {
    if ( config.sat_preprocess_booleans != 0
      || config.sat_preprocess_theory != 0 )
      opensmt_warning( "not using SMT-preprocessing with interpolation" );
    state = solver.smtSolve( false );
  }

  // If computation has been stopped, return undef
  if ( opensmt::stop ) state = l_Undef;
}
Ejemplo n.º 25
0
Archivo: main.cpp Proyecto: CCJY/coliru
 std::ostream& operator()(std::ostream& os, Value const& ctx, mustache::sequence const& v) const {
     for(auto& element : v)
         boost::apply_visitor(std::bind(expander(), std::ref(os), std::placeholders::_1, std::placeholders::_2), ctx, element);
     return os;
 }
Ejemplo n.º 26
0
Archivo: tests.cpp Proyecto: fanioz/ddh
void online_jps_test()
{
	bool check_opt = false;
	//bool check_opt = true;
	warthog::scenario_manager scenmgr;
	scenmgr.load_scenario("orz700d.map.scen");
	warthog::gridmap map(scenmgr.get_experiment(0)->map().c_str());

//	warthog::gridmap map("CSC2F.map", true);
//	map.printdb(std::cerr);
//	map.print(std::cerr);
//	exit(1);

	warthog::jps_expansion_policy expander(&map);
	warthog::octile_heuristic heuristic(map.width(), map.height());

	warthog::flexible_astar<
		warthog::octile_heuristic,
	   	warthog::jps_expansion_policy> astar(&heuristic, &expander);
	//astar.set_verbose(true);

	for(unsigned int i=0; i < scenmgr.num_experiments(); i++)
	{
		warthog::experiment* exp = scenmgr.get_experiment(i);

		int startid = exp->starty() * exp->mapwidth() + exp->startx();
		int goalid = exp->goaly() * exp->mapwidth() + exp->goalx();
		double len = astar.get_length(startid, goalid);
		if(len == warthog::INF)
		{
			len = 0;
		}

		if(!check_opt)
			continue;

		std::cerr << "exp "<<i<<" ";
		exp->print(std::cerr);
		std::cerr << " (ne=" << astar.get_nodes_expanded() << 
			" ng=" << astar.get_nodes_generated() << 
			" nt=" << astar.get_nodes_touched() <<
			" st=" << astar.get_search_time() <<")";
		std::cerr << std::endl;

		std::stringstream stroptlen;
		stroptlen << std::fixed << std::setprecision(exp->precision());
		stroptlen << exp->distance();

		std::stringstream strpathlen;
		strpathlen << std::fixed << std::setprecision(exp->precision());
		strpathlen << len;

		if(stroptlen.str().compare(strpathlen.str()))
		{
			std::cerr << std::setprecision(6);
			std::cerr << "optimality check failed!" << std::endl;
			std::cerr << std::endl;
			std::cerr << "optimal path length: "<<stroptlen.str()
				<<" computed length: ";
			std::cerr << strpathlen.str()<<std::endl;
			std::cerr << "precision: " << exp->precision()<<std::endl;
			exit(1);
		}
	}
	std::cerr << "done. total memory: "<< astar.mem() + scenmgr.mem() << "\n";

}
Ejemplo n.º 27
0
Archivo: main.cpp Proyecto: CCJY/coliru
 void operator()(std::ostream& os, Ctx const& ctx, mustache::section const& v) const {
     if (v.sense == truthiness(ctx))
         expander()(os, Value(ctx), v.content);
 }