Пример #1
0
Файл: genKPK.cpp Проект: hof/qm2
 /**
  * Calculate table index
  * 
  * @return {int} table index (range: 0 .. MAX_IDX) 
  * 
  * | 0-5        | 6-7            | 8-10
  * | wk (0..63) | wp file (0..3) | wp rank (0..5)
  */
 inline int index(int wk, int wp) {
     int result = wk + (FILE(wp) << 6) + ((RANK(wp) - 1) << 8);
     assert(result >= 0 && result < MAX_IDX);
     assert(FILE(wp) <= 3);
     assert(RANK(wp) <= 6);
     return result;
 }
Пример #2
0
void open_directory(GNode *directory)
{
	if (FILE(directory)->read == FALSE && read_directory(directory) == FALSE)
		return;

	FILE(directory)->open = TRUE;
	add_directory_content(directory);
	update_last_line();
	print_lines(g_list_next(FILE(directory)->line), last_line, TRUE);
}
Пример #3
0
void remove_watch_directory(GNode *directory, gboolean remove_watch)
{
	CHECK_INOTIFY_ENABLED();
	if (FILE(directory)->watch == -1)
		PRINT_ERROR_INFO("Directory doesn't have a watch associated");
	else if (remove_watch && inotify_rm_watch(inotify_descriptor, FILE(directory)->watch) == -1)
		PRINT_ERRNO_INFO();
	else if (g_hash_table_remove(watches_table, &(FILE(directory)->watch)) == FALSE)
		PRINT_ERROR_INFO("Element removal failed in watches_table");
}
Пример #4
0
gboolean insert_in_tree(GNode *directory, File *file)
{
	GNode *new_file, *file_ptr, *dir_ptr;
	int position;

	if (file->name[0] == '.' && FILE(directory)->show_dotfiles == FALSE) {
		insert_sorted_in_dotfiles(directory, file);

		return FALSE;
	}

	new_file = insert_sorted_in_tree(directory, file);
	for (dir_ptr = directory; !G_NODE_IS_ROOT(dir_ptr); dir_ptr = dir_ptr->parent) {
		if (FILE(dir_ptr)->open == FALSE)
			return FALSE;
	}
	if (FILE(dir_ptr)->open == FALSE)
		return FALSE;

	file_ptr = get_previous_file(new_file);
	position = g_list_position(lines, FILE(file_ptr)->line);
	lines = g_list_insert(lines, new_file, position + 1);
	file->line = g_list_nth(lines, position + 1);

	if (g_list_length(first_line) - g_list_length(last_line) + 1) {
		if (g_list_previous(first_line) == file->line)
			first_line = file->line;
		else if (g_list_next(last_line) == file->line)
			last_line = file->line;
	}
	if (g_list_position(lines, first_line) <= position + 1 &&
			position + 1 <= g_list_position(lines, last_line)) {
		if (position + 1 < g_list_position(lines, selected_line)) {
			if (g_list_length(first_line) <= getmaxy(tree_window))
				print_lines(first_line, last_line, FALSE);
			else {
				first_line = g_list_next(first_line);
				print_lines(first_line, file->line, FALSE);
			}
		} else {
			if (g_list_length(first_line) > getmaxy(tree_window))
				last_line = g_list_previous(last_line);

			if (g_node_last_sibling(new_file) == new_file)
				print_lines(g_list_previous(file->line), last_line, FALSE);
			else
				print_lines(file->line, last_line, FALSE);
		}

		return TRUE;
	}

	return FALSE;
}
Пример #5
0
void close_directory(GNode *directory)
{
	GNode *directory_sibling;
	GList *line_ptr;

	directory_sibling = get_next_file_not_deepper(directory);

	for (line_ptr = g_list_next(FILE(directory)->line); line_ptr != NULL &&
			NODE(line_ptr) != directory_sibling; line_ptr = g_list_next(FILE(directory)->line))
		lines = g_list_delete_link(lines, line_ptr);

	FILE(directory)->open = FALSE;
	update_last_line();
	print_lines(g_list_next(FILE(directory)->line), last_line, TRUE);
}
Пример #6
0
void add_directory_content(GNode *directory)
{
	GNode *file_ptr, *directory_sibling;
	int position;

	directory_sibling = get_next_file_not_deepper(directory);

	for (position = g_list_position(lines, FILE(directory)->line) + 1,
			file_ptr = g_node_first_child(directory);
			file_ptr != NULL && file_ptr != directory_sibling;
			position++, file_ptr = get_next_file(file_ptr)) {
		lines = g_list_insert(lines, file_ptr, position);
		FILE(file_ptr)->line = g_list_nth(lines, position);
	}
}
Пример #7
0
void TEST(Meshes2) {
  ors::Mesh mesh1,mesh2;
  OpenGL gl;
  gl.add(drawInit,0);
  gl.add(ors::glDrawMesh,&mesh1);
  mesh1.readTriFile(FILE("z.e3.tri"));
  mesh2.readTriFile(FILE("z.e3.tri"));
  uint i,m=0; double my=mesh1.V(m,1);
  for(i=0;i<mesh1.V.d0;i++) if(mesh1.V(i,1)>mesh1.V(m,1)){ m=i; my=mesh1.V(m,1); }
  mesh2.translate(0,my,0);
  mesh1.addMesh(mesh2);
  //mesh1.writeTriFile(("z.e3.tri"));
  //mesh1.writeOffFile(("z.e3.off"));
  gl.watch();
}
ObjFunction2  Overall_Optimisation_Configuration_Settings::read_vector_from_file(char const *filename, char const *file_description, const int elements,const int necessary){
	ObjFunction2 ObjPnt(elements,1111.0);
	std::cout << std::endl << file_description << " file ...";
	std::ifstream FILE(filename);
	if( FileExists(filename) ){
		std::cout << " OK!"<< std::endl;

		if(FILE.is_open()){

			double buff=0.0;
			std::vector<double> buff_vec;

			while(FILE>>buff)
				buff_vec.push_back(buff);

			if(buff_vec.size()==ObjPnt.size()){
				for (unsigned int i=0; i<ObjPnt.size() ; ++i)
					ObjPnt[i]=buff_vec[i];
			}else
				ObjPnt= ObjFunction2(elements,buff_vec[0]);

			FILE.close();
			std::cout << "\t"<< file_description<< " read: " << ObjPnt << std::endl;
			return ObjPnt;
		}else{
Пример #9
0
HumanBrain::HumanBrain(int _nrInNodes, int _nrOutNodes, int _nrHiddenNodes, shared_ptr<ParametersTable> _PT) :
		AbstractBrain(_nrInNodes, _nrOutNodes, _nrHiddenNodes, _PT) {
	useActionMap = (PT == nullptr) ? useActionMapPL->lookup() : PT->lookupBool("BRAIN_HUMAN-useActionMap");
	actionMapFileName = (PT == nullptr) ? actionMapFileNamePL->lookup() : PT->lookupString("BRAIN_HUMAN-actionMapFileName");



	if (useActionMap) {  // if using an action map, load map with lines of format char output1 output2 output3... file must match brain # of outputs
		string fileName = actionMapFileName;
		ifstream FILE(fileName);
		string rawLine;
		double readDouble;
		char readChar;
		vector<double> action;
		if (FILE.is_open()) {  // if the file named by actionMapFileName can be opened
			while (getline(FILE, rawLine)) {  // keep loading one line from the file at a time into "line" until we get to the end of the file
				std::stringstream ss(rawLine);
				ss >> readChar;  // pull one char, this will be the key to the map
				action.clear();
				for (int i = 0; i < nrOutNodes; i++) {  // pull one double for each output
					ss >> readDouble;  // read one double
					action.push_back(readDouble);
				}
				ss >> actionNames[readChar];
				actionMap[readChar] = action;
			}
		} else {
			cout << "\n\nERROR:HumanBrain constructor, unable to open file \"" << fileName << "\"\n\nExiting\n" << endl;
			exit(1);
		}
	}
Пример #10
0
void add_watch_directory(GNode *directory)
{
	char *path;
	int watch;

	CHECK_INOTIFY_ENABLED();
	path = get_path(directory);
	if ((watch = inotify_add_watch(inotify_descriptor, path, IN_CREATE | IN_MOVED_FROM |
					IN_MOVED_TO | IN_DELETE)) == -1)
		PRINT_ERRNO_INFO();
	else {
		FILE(directory)->watch = watch;
		g_hash_table_insert(watches_table, &(FILE(directory)->watch), directory);
	}
	free(path);
}
Пример #11
0
void read_in_files(){
  std::ifstream FILE(path);
  std::string str;

  while(std::getline(FILE,str)){
    std::vector<unsigned long long> tmp;
    unsigned long long i=0;
    unsigned long long lasti=0;
    for(;i<str.size();i++){
      if(str[i]==',' || i==str.size()-1){
        unsigned long long val=std::stoull(str.substr(lasti,i+1-lasti),nullptr,10);
        tmp.push_back(val);
        lasti=i+1;
      }
    }
    src_file.push_back(tmp);
  }

  FILE.close();

  input_freqs=std::vector<double>(src_file[1].size());
  std::ifstream FILE2 (input_freqs_path);

  while(std::getline(FILE2,str)){
    int input=std::stoi(str.substr(0,1),nullptr,10);
    double freq=std::stod(str.substr(2,str.size()-2),nullptr);
    input_freqs[input]=freq;

  }
  FILE2.close();



}
vector<Point> generateCircle(Point center, int radius, const char* filename)
{
    vector<Point> P;
    for(int x = -radius; x<radius; x++)
    {
        int y = round(sqrt(radius*radius-x*x));
        P.push_back(Point(center[0]+x,center[1]+y));
    }
    for(int x = radius; x>-radius; x--)
    {
        int y = -round(sqrt(radius*radius-x*x));
        P.push_back(Point(center[0]+x,center[1]+y));
    }

    if(filename != NULL)
    {
        /* save into files */
        std::ofstream FILE(filename);
        for(vector<Point>::const_iterator it = P.begin(); it != P.end(); it++) {
            FILE << (*it)[0]<<" "<<(*it)[1] <<'\n';
        }
        /* save into files */
    }
    return P;
}
vector<PointD> generateSegment(PointD startPoint, PointD endPoint, double step, const char* filename)
{
    vector<PointD> P;
    //AB: y = a x + b where a = dy/dx and b = yA - a(xA)
    double dx = endPoint[0] - startPoint[0] , dy = endPoint[1] - startPoint[1];
    double x, y;
    if(dx == 0) //vertical line
    {
        x = startPoint[0];
        if(startPoint[1]<endPoint[1])
            for(y = startPoint[1]; y <= endPoint[1]; y += step)
                P.push_back(PointD(x,y));
        else
            for(y = startPoint[1]; y >= endPoint[1]; y -= step)
                P.push_back(PointD(x,y));
    }
    else
    {
        double a = dy/dx;
        double b = startPoint[1] - a*startPoint[0];
        if(startPoint[0]<endPoint[0])
            for(x = startPoint[0]; x <= endPoint[0]; x += step)
                P.push_back(PointD(x,a*x+b));
        else
            for(x = startPoint[0]; x >= endPoint[0]; x -= step)
                P.push_back(PointD(x,a*x+b));
    }
    /* save into files */
    std::ofstream FILE(filename);
    for(vector<PointD>::const_iterator it = P.begin(); it != P.end(); it++) {
        FILE << (*it)[0]<<" "<<(*it)[1] <<'\n';
    }
    /* save into files */
    return P;
}
Пример #14
0
vector<vector<string>> GBCsv::parseCsv(const string& csvPath)
{
	Data data = FILE()->getDataFromFile(csvPath);
	vector<vector<string>> v = parseCsv(data.getBytes(), data.getSize());
	data.clear();

	return v;
}
Пример #15
0
	int gbupdate_lua_loader(lua_State * L)
	{
		static const std::string FILE_EXT = ".lua";
		std::string filename(luaL_checkstring(L, 1));

		Data chunk;
		size_t pos = filename.rfind(FILE_EXT);
		if (pos == filename.length() - FILE_EXT.length())
		{
			filename = filename.substr(0, pos);
		}

		pos = filename.find_first_of(".");
		while (pos != std::string::npos)
		{
			filename.replace(pos, 1, "/");
			pos = filename.find_first_of(".");
		}

		do
		{
			GBUpdateInfo * pInfo = GBUpdate::getInstance()->getUpdateInfo(StringUtils::format("src/%s%s", filename.c_str(), FILE_EXT.c_str()));
			if (!pInfo)
				break;

			if (FILE()->isFileExist(pInfo->location))
			{
				chunk = FILE()->getDataFromFile(pInfo->location);
				break;
			}
		} while (false);

		if (chunk.getBytes())
		{
			LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
			stack->luaLoadBuffer(L, (char*)chunk.getBytes(), (int)chunk.getSize(), filename.c_str());
			chunk.clear();
		}
		else
		{
			CCLOG("can not get file data of %s", filename.c_str());
			return 0;
		}

		return 1;
	}
Пример #16
0
void init_lines(void)
{
	lines = g_list_append(lines, tree_root);
	FILE(tree_root)->line = lines;
	selected_line = lines;
	first_line = lines;
	update_last_line();
}
Пример #17
0
void init_ui(char *name)
{
	init_curses();
	init_tree(name);
	init_lines();
	print_line(FILE(tree_root)->line);
	open_directory(tree_root);
	refresh_screen();
}
Пример #18
0
void update_directory(GNode *directory)
{
	close_directory(directory);
	destroy_directory_content(directory);
	open_directory(directory);

	if (FILE(directory)->show_dotfiles == TRUE)
		show_dotfiles(directory);
}
Пример #19
0
std::string SqToStr( int sq )
{
    char file = FILE(sq);
    char rank = RANK(sq);
    char buf[3];
    buf[0] = file;
    buf[1] = rank;
    buf[2] = '\0';
    std::string s = buf;
    return s;
}
Пример #20
0
void select_previous_line_by_first_letter(char letter)
{
	GList *line_ptr;

	for (line_ptr = g_list_previous(selected_line); line_ptr != NULL;
			line_ptr = g_list_previous(line_ptr)) {
		if (FILE(NODE(line_ptr))->name[0] == letter) {
			select_line(line_ptr);
			return;
		}
	}
}
Пример #21
0
GNode *search_node_by_name(GNode *directory, char *name)
{
	GNode *file_ptr;

	for (file_ptr = g_node_first_child(directory); file_ptr != NULL;
			file_ptr = g_node_next_sibling(file_ptr)) {
		if (!strcmp(FILE(file_ptr)->name, name))
			return file_ptr;
	}

	return NULL;
}
Пример #22
0
void GBUpdate::onDownloadSuccess(const DownloadTask& task)
{
	string url = task.requestURL;
	string path = task.storagePath;
	string custom = task.identifier;
	if (custom == "md5")
	{		
		_downloadList.clear();
		vector<vector<string>> v = GBCsv::parseCsv(GBUtils::getExternalPath(custom));
		for (unsigned int i = 1; i < v.size(); i++)
		{
			string key = v[i][0];
			string md5 = v[i][1];
			unsigned int size = atoi(v[i][2].c_str());
			if (_updateInfos.find(key) == _updateInfos.end() || _updateInfos[key].md5 != md5)
			{
				GBUpdateInfo info = { key, md5, _remoteVersion, "", size };
				_downloadList[key] = info;				
			}
		}
		if (getDownloadTotalSize() > MIN_DOWNLOAD_SIZE && !_isAutoUpdate)
		{
			DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_READY);
		}
		else
		{
			DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_START);
		}		
	}
	else
	{
		if (_downloadList.find(custom) != _downloadList.end())
		{
			Data data = FILE()->getDataFromFile(path);
			if (data.getBytes())
			{
				auto md5 = new MD5(data.getBytes(), data.getSize());
				if (md5->toStr() == _downloadList[custom].md5)
				{
					_downloadList[custom].location = GBUtils::getExternalPath(custom);
					DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATED_ONE, &_downloadList[custom]);
				}
				else
					_downloader->createDownloadFileTask(url, path, custom);
			}
			else
				_downloader->createDownloadFileTask(url, path, custom);
			data.clear();
		}
	}
}
Пример #23
0
Файл: genKPK.cpp Проект: hof/qm2
 void init() {
     bool success;
     uint8_t temp[2][64][MAX_IDX];
     int step = 0;
     int unknowns;
     do {
         unknowns = 0;
         success = false;
         //iterate though all possible positions
         for (int wk = a1; wk <= h8; wk++) {
             for (int bk = a1; bk <= h8; bk++) {
                 for (int wp = a2; wp <= h7; wp++) {
                     if (FILE(wp) > 3) {
                         continue;
                     }
                     int idx = index(wk, wp);
                     uint8_t * result_w = &temp[WHITE][bk][idx];
                     uint8_t * result_b = &temp[BLACK][bk][idx];
                     if (step == 0) { //initialize
                         KPK_BB[WHITE][idx] = 0;
                         KPK_BB[BLACK][idx] = 0;
                         *result_w = eval(WHITE, wk, bk, wp);
                         *result_b = eval(BLACK, wk, bk, wp);
                         success = true;
                     } else {
                         if (*result_w == UNKNOWN) {
                             unknowns++;
                             *result_w = classify_w(wk, bk, wp, temp);
                             success |= *result_w != UNKNOWN;
                         }
                         if (*result_b == UNKNOWN) {
                             unknowns++;
                             *result_b = classify_b(wk, bk, wp, temp);
                             success |= *result_b != UNKNOWN;
                         }
                     }
                     if (*result_w == WIN) {
                         KPK_BB[WHITE][idx] |= BIT(bk);
                     }
                     if (*result_b == WIN) {
                         KPK_BB[BLACK][idx] |= BIT(bk);
                     }
                 }
             }
         }
         step++;
     } while (success);
     std::cout << "Generated KPK bitbase in " << (step - 1) << " steps\n";
     std::cout << "Unknown classifications: " << unknowns;
     std::cout << "\nTesting (K,P,K) = (h3, b7, h2): WIN=" << probe(WHITE, h3, b7, h2);
 }
Пример #24
0
void TEST(Meshes3) {
  ors::Mesh mesh;
  OpenGL gl;
  gl.add(drawInit,0);
  gl.add(ors::glDrawMesh,&mesh);
  //MeshSetSphere(mesh,0);
  mesh.readTriFile(FILE("z.e4.tri"));
  gl.reportSelects=true;
  gl.watch();
  cout <<gl.topSelection->name <<endl;
  uint i=gl.topSelection->name >> 4;
  mesh.skin(i);
  gl.watch();
}
Пример #25
0
void TEST(Meshes) {
  OpenGL gl;
  ors::Mesh mesh;
  mesh.readStlFile(FILE("../../../data/pr2_model/head_v0/head_pan.stl"));
  mesh.scale(.001);
  mesh.writeTriFile(("z.full.tri"));
  mesh.fuseNearVertices(1e-6);
  mesh.writeTriFile(("z.e4.tri"));
  mesh.fuseNearVertices(1e-5);
  mesh.writeTriFile(("z.e3.tri"));
  mesh.fuseNearVertices(1e-4);
  mesh.writeTriFile(("z.e2.tri"));
  gl.add(drawInit,0);
  gl.add(ors::glDrawMesh,&mesh);
  gl.watch();
}
Пример #26
0
/** the param ARGV[0] was changed such as to be the folder name of the executable (working directory) */
list< map<string, string> >&
SimRunner::readInputFile( int ARGC, char **ARGV ) {
    FileParser Reader;
    map< string, vector<string> >* pParams;

    char default_file[15]="quantiNemo.ini";

    // check if the name of the settings file is passed
    if (ARGC == 1) { // if no argument is passed use the default file name
        // is there a default settings file?
        ARGV[1] = default_file;
        ifstream FILE(((string)ARGV[0]+ARGV[1]).c_str());
        if(!FILE) {   // no default settings file
            message("\nPlease enter the settings file name: ");
            cin >> ARGV[1];
        }
Пример #27
0
void usage(void)
{
    fprintf(stderr, "FIDOGATE %s  %s %s\n\n",
	    version_global(), PROGRAM, version_local(VERSION) );
    
    fprintf(stderr, "usage:   %s [-options]\n\n", PROGRAM);
    fprintf(stderr, "\
options: -b --news-batch              (passed on as -b)\n\
         -n --news-mode               (passed on as -n)\n\
         -f --batch-file FILE         (passed on as -f FILE)\n\
	 -m --maxmsg N                (passed on as -m N)\n\
\n\
	 -h --help                    this help\n");

    exit(0);
}
Пример #28
0
char*
StringPosition(Position pos)
{
  char ret[2+1];

  // Unsigned so we don't need to check < 0.
  if(pos > 63) {
    return strdup("#invalid position");
  }

  if(sprintf(ret, "%c%d", 'a'+FILE(pos), RANK(pos)+1) != 2) {
    panic("Couldn't string position");
  }

  ret[2] = '\0';

  return strdup(ret);
}
vector<PointD> generateArc(PointD center, double radius, double angleStart, double angleEnd, const char* filename)
{
    vector<PointD> P;
    double step = 1/radius;
    if(angleStart<angleEnd)
        for(double theta = angleStart; theta<angleEnd; theta += step)
            P.push_back(PointD(center[0]+radius*sin(theta), center[1]+radius*cos(theta)));
    else
        for(double theta = angleEnd; theta<angleStart; theta += step)
            P.push_back(PointD(center[0]+radius*sin(theta), center[1]+radius*cos(theta)));
    /* save into files */
    std::ofstream FILE(filename);
    for(vector<PointD>::const_iterator it = P.begin(); it != P.end(); it++) {
        FILE << (*it)[0]<<" "<<(*it)[1] <<'\n';
    }
    /* save into files */
    return P;
}
vector<PointD> generateCircle(PointD center, double radius, const char* filename)
{
    vector<PointD> P;
    /*
     * x = sin(theta)*r
     * y = cos(theta)*r
    */
    double step = 1/radius;
    for(double theta = 0; theta<2*M_PI; theta += step)
        P.push_back(PointD(center[0]+radius*sin(theta), center[1]+radius*cos(theta)));
    /* save into files */
    /*
    std::ofstream FILE(filename);
    std::ostream_iterator<PointD> output_iterator(FILE, "\n");
    std::copy(P.begin(), P.end(), output_iterator);
    */
    std::ofstream FILE(filename);
    for(vector<PointD>::const_iterator it = P.begin(); it != P.end(); it++) {
        FILE << (*it)[0]<<" "<<(*it)[1] <<'\n';
    }
    /* save into files */

    return P;
}