Exemplo n.º 1
0
/**
 * 为重新进行索引内部数据的整理,  解析配置文件, 初始化 index_lib 内部的builder
 *
 * @param   config  xml的配置节点。  内部的子节点包括了 索引的各个配置项
 *         样例:
 *         <indexLib>
 *            <index    path="/dir" />
 *         </indexLib>
 *
 * @return  0: success ;   -1: 程序处理失败
 */
int init_rebuild( mxml_node_t * config )
{
    mxml_node_t  * modulesNode  = NULL;
    mxml_node_t  * indexLibNode = NULL;               // index_lib的根节点
    mxml_node_t  * profileNode  = NULL;               // profile配置节点
    mxml_node_t  * indexNode    = NULL;               // index配置节点
    mxml_node_t  * idDictNode   = NULL;               // nid->docId 字典及deletemap节点

    modulesNode  = mxmlFindElement(config, config, "modules", NULL, NULL, MXML_DESCEND);
    if ( modulesNode == NULL || modulesNode->parent != config )
    {
        TERR("can't find modules's node");
        return -1;
    }

    indexLibNode = mxmlFindElement(modulesNode, modulesNode, "indexLib", NULL, NULL, MXML_DESCEND);
    // 检查节点有效性
    if ( indexLibNode == NULL || indexLibNode->parent != modulesNode )
    {
        TERR("can't find indexLib's node");
        return -1;
    }

    // 获取配置节点
    profileNode  = mxmlFindElement(indexLibNode, indexLibNode, "profile",  NULL, NULL, MXML_DESCEND);
    indexNode    = mxmlFindElement(indexLibNode, indexLibNode, "index",    NULL, NULL, MXML_DESCEND);
    idDictNode   = mxmlFindElement(indexLibNode, indexLibNode, "idDict",   NULL, NULL, MXML_DESCEND);

    // 检查节点有效性
    if ( profileNode == NULL || profileNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node profile");
        return -1;
    }

    if ( indexNode == NULL || indexNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node index");
        return -1;
    }

    if ( idDictNode == NULL || idDictNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node idDict");
        return -1;
    }

    // 开始 初始化 各个模块
    if ( initProfile(    mxmlElementGetAttr(profileNode,  "path" ), false, true ) )  return -1;
    if ( initIdDict (    mxmlElementGetAttr(idDictNode,   "path" ), false) )  return -1;
    if ( initFullIndex(  mxmlElementGetAttr(indexNode,    "path" ) ) )  return -1;
    if ( initIdxBuilder( mxmlElementGetAttr(indexNode,    "path" ) ) )  return -1;

    return 0;
}
Exemplo n.º 2
0
void initProfiles()
{

	profile_1 = malloc(sizeof(Profile));
	profile_2 = malloc(sizeof(Profile));
	profile_3 = malloc(sizeof(Profile));



	initProfile(profile_1, 1);
	initProfile(profile_2, 2);
	initProfile(profile_3, 3);

	// Set the current profile to a temporary anonymous profile


	 printf("finished init! \n");
	 printf("profile 1 score: %i \n", (*profile_1).score);
	 printf("profile 2 score: %i \n", (*profile_2).score);

	 return;
}
/****************************************************************************
NAME
    handleClInitCfm

DESCRIPTION
    Handles the CL library initialisation result.

*/
static void handleClInitCfm(const CL_INIT_CFM_T *cfm)
{
    mvdAppState app_state = the_app->app_state;
    
    switch (app_state)
    {
        case AppStateInitialising:
        {
            if (cfm->status == success)
            {
                /* Configure Mode4 Security Settings */
                ConnectionSmSecModeConfig(&the_app->task, cl_sm_wae_acl_owner_none, FALSE, TRUE);
                
                /* Turn off all SDP security */
                ConnectionSmSetSecurityLevel(protocol_l2cap, 1, ssp_secl4_l0, TRUE, FALSE, FALSE);
                
                if (cfm->version == bluetooth2_1)
                {
                    /* EIR inquiry mode */
                    ConnectionWriteInquiryMode(&the_app->task, inquiry_mode_eir);
                }
                
                /* Set default role switch policy */
                ConnectionSetRoleSwitchParams(NULL);
                
                initProfile();
            }
            else
            {
                DEBUG_CL((" App failed to init CL\n"));
                Panic();
            }
            break;
        }    
        default:
        {
            unexpectedClMessage(app_state, CL_INIT_CFM);
            break;
        }
    }
}
Exemplo n.º 4
0
void bTrack::makeBinTrack(){
	Timer tm;
	verb ("******   Make binary track <%s>   ******\n", name);
	writeLog("    Make binary track <%s>\n",name);
	//===================================================== prepare track file name
	if (pcorProfile!=0)	 verb("===          pcorProfile=  <%s>\n",pcorProfile);
	trackType=getTrackType(name);
	//=====================================================================================
	initProfile();                   					//============ Allocate arrays
	char pfil[4096];
	readInputTrack(makeFileName(pfil,trackPath,name));		//============ Read tracks
	//======================================================================

	verb("Finalize profiles... \n");
	finProfile(); //============ Calculate min,max,average; convert to bytes
	verb("Write profiles... \n");
	writeProfilePrm();
	writeByteProfile();					//============ write binary profiles
	writeLog("    Make binary track -> OK. Time=%s\n",tm.getTime());

	return;
}
Exemplo n.º 5
0
static
void printCountmatAndSites(Profile *countmat, int *sites, double *scorePerSite, Dataset *data)
{
	updateCountmatFromSites(countmat, sites, data);
	Profile *profile = initProfile(countmat->span, countmat->maxspan);
	copyProfile(profile, countmat);

	//normalize "profile"
	for(int x = 0; x < countmat->span; x++) {
		if( !profile->isgap[x]) {
			double sum = 0.0;
			for(int y = 0; y < NUMALPHAS; y++) {
				sum += profile->mat[x][y];
			}
			for(int y = 0; y < NUMALPHAS; y++) {
				profile->mat[x][y] /= sum;
			}
		}
	}

	/* print profile */
	printf("Motif profile generated from sites:\n"); 
	printProfile(stdout, profile);

	printf("Flanking regions:\n"); 
	printFlankingRegionProfile(stdout, sites, countmat->span, data);


	/* NOW, PRINT CONSENSUS MOTIF */
	printf("Motif span: %d\n", profile->span);
	printf("Motif weight/width: %d\n", profile->cols);
	printf("Consensus motif: ");
	for(int x=0; x< profile->span; x++) {
		if(!profile->isgap[x]) {
			if(profile->mat[x][0] > 0.5) 
				printf("A");
			else if(profile->mat[x][1] > 0.5) 
				printf("C");
			else if(profile->mat[x][2] > 0.5) 
				printf("G");
			else if(profile->mat[x][3] > 0.5) 
				printf("T");
			else 
				printf("N");
		}
		else {
			printf("_");
		}
	}
	printf("\n");

	int numsites = getNumSites(sites, data->numseqs);
	printf("Number of predicted sites: %d (%.2lf%%)\n", numsites, (numsites * 100.0) / data->numseqs);
	printf("\n");

	if(profile->span != profile->cols) {
		printGapPos(stdout, profile);
		printf("\n");
	}

	printf("Sequence range is from 0 to (number of sequences - 1).\n");
	printf("Motif sites are in range 1 to length or -1 to -length.\n");
	for(int i=0; i< data->numseqs; i++) {
		if(sites[i] >= 0) {
			int pos = getConcat2DoubleStrandPos(data,i,sites[i]);
			int revcomplPos = getConcat2DoubleStrandPos(data, i, getConcatPosOfOppStrand(data, i, sites[i], profile->span));
			printf("Sequence %3d: motif site %6d  (%6d)\n",i, pos, revcomplPos);
		}
		else {
			printf("Sequence %3d: motif site %6s  (%6s)\n",i, "none", "none");
		}
	}
	

	printf("\n");
	printf("Alignments and FASTA-headers:\n");
	printAlignment(stdout, sites, profile->span, scorePerSite, data);
	printf("\n");
	if(numsites < data->numseqs) {
		printf("FASTA-header of sequences with zero occurrences:\n");
		printZeroOccurrencesSeqHeaders(stdout, sites, data);
		printf("\n");
	}
	nilProfile(profile);
}
Exemplo n.º 6
0
int moveToLocation(int trainNum, int source, int dest, track_node *track, int doReverse, int speed, int *velocity) {
  struct Path path;
  struct VelocityProfile profile;

  BFS(source, dest, track, &path, doReverse);
  if((path.node[path.numNodes-2])->reverse == path.node[path.numNodes-1]) {
    path.numNodes--;
  }

  int periodic = Create(2, periodicTask);

  initProfile(&profile, trainNum, speed, &path, source, periodic, velocity);

  int curNode = 1;

  profile.location = curNode-1;

  int timeout = false;
  int switchNode, switchDistance;
  Putc2(1, (char)speed, (char)trainNum);
  setAccelerating(&profile);

  while(curNode < path.numNodes) {
    if((path.node[curNode-1])->reverse == path.node[curNode]) {
      waitForStop(&profile);
      if(curNode != 1) {
        profile.displayLocation = curNode;
        profile.delta = -300000;
      }
      Putc2(1, (char)15, (char)trainNum);
      Putc2(1, (char)speed, (char)trainNum);
      setAccelerating(&profile);
    }

    profile.reverseNode = findNextReverseNode(&path, curNode);
    int offset = 0;
    while(curNode+offset < path.numNodes) {
      switchNode = distanceBefore(&path, (profile.velocity)[speed]*50, curNode+offset, &switchDistance);
      if((path.node[curNode+offset])->type == NODE_BRANCH && switchNode == curNode-1) {
	if(switchDistance >= 0) {
          waitForDistance(&profile, switchDistance);
	}
	if(adjDirection(path.node[curNode+offset], path.node[curNode+offset+1]) == DIR_STRAIGHT) {
	  setSwitchState((path.node[curNode+offset])->num, 'S');
	}else{
	  setSwitchState((path.node[curNode+offset])->num, 'C');
	}
      }else if(switchNode > curNode-1) {
	break;
      }
      offset++;
    }

    if(curNode == path.numNodes-1) break;

    int distance = adjDistance(path.node[curNode-1], path.node[curNode]);
    if(curNode == 1 && (path.node[0])->reverse == path.node[1]) {
    }else if((path.node[curNode])->type == NODE_SENSOR) {
      int reply;
      int sensorNum = (path.node[curNode])->num;
      int sensorTask = Create(2, sensorWaitTask);
      Send(sensorTask, (char *)&sensorNum, sizeof(int), (char *)&reply, sizeof(int));

      int src = waitForDistance(&profile, distance+150000);
      if(src == periodic) {
	printf("timeout at sensor %s\r", (path.node[curNode])->name);
        timeout = true;
      }else{
	float err = profile.delta/1000 - distance/1000;
	printf("distance error at node %s: %dmm\r", (path.node[curNode])->name, (int)err);
      }
      Destroy(sensorTask);
    }else{
      waitForDistance(&profile, distance);
    }

    setLocation(&profile, curNode);
    curNode++;
    if(timeout) {
      profile.delta = 150000;
      timeout = false;
    }
  }
  int reply;
  int sensorNum = (path.node[curNode])->num;
  int sensorTask = Create(2, sensorWaitTask);
  Send(sensorTask, (char *)&sensorNum, sizeof(int), (char *)&reply, sizeof(int));

  int distance = adjDistance(path.node[curNode-1], path.node[curNode]);
  int src = waitForDistanceOrStop(&profile, distance);
  if(src == periodic) {
    printf("timeout at sensor %s\r", (path.node[curNode])->name);
  }else{
    float err = profile.delta/1000 - distance/1000;
    printf("distance error at node %s: %dmm\r", (path.node[curNode])->name, (int)err);
  }
  Destroy(sensorTask);

  setLocation(&profile, path.numNodes-1);
  waitForStop(&profile);
  Destroy(periodic);

  int curLocation = 0;
  while(curLocation < TRACK_MAX && strcmp(track[curLocation].name, 
					  (path.node[path.numNodes-1])->name) != 0) curLocation++;

  return curLocation;
}
Exemplo n.º 7
0
void bTrack::initProfile(){
	initProfile(0);
};
Exemplo n.º 8
0
GameScene::GameScene(QWidget *parent) :
    QGraphicsScene(parent),
    myLock(false)
{
  inputDisabled = true;

  dconfirm = new ConfirmDialog();
  addWidget(dconfirm, Qt::FramelessWindowHint);
  dconfirm->hide();

  menu = new MenuWidget();
  addWidget(menu);
  menu->activate();

  connect(menu, SIGNAL(menuNew()), this, SLOT(on_menuNew()));
  connect(menu, SIGNAL(menuContinue()), this, SLOT(on_menuContinue()));
  connect(menu, SIGNAL(menuExit()), this, SLOT(on_menuExit()));
  connect(menu, SIGNAL(menuPauseBack()), this, SLOT(on_menuPauseBack()));
  connect(menu, SIGNAL(menuRestartLevel()), this, SLOT(on_menuRestartLevel()));
  connect(menu, SIGNAL(menuAbandonGame()), this, SLOT(on_menuAbandonGame()));
  connect(menu, SIGNAL(menuThemeChanged()), this, SLOT(on_menuThemeChanged()));
  connect(menu, SIGNAL(menuGameStart()), this, SLOT(on_menuGameStart()));
  connect(menu, SIGNAL(menuLevelPack()), this, SLOT(on_menuLevelPack()));

  stat = new StatInfo();

  connect(gameProfile, SIGNAL(profileChanged()), this, SLOT(initProfile()));

  rows = cols = 0;

  xoff = 20;
  yoff = 10;

  advanceTimer = new QTimer(this);
  advanceTimer->setInterval(30);
  connect(advanceTimer, SIGNAL(timeout()), this, SLOT(nextCycle()));

  timeTimer = new QTimer(this);
  timeTimer->setInterval(1000);
  connect(timeTimer, SIGNAL(timeout()), this, SLOT(countTime()));

  bonusTimer = new QTimer(this);
  bonusTimer->setInterval(500);
  connect(bonusTimer, SIGNAL(timeout()), this, SLOT(countBonusTime()));

  hintTimer = new QTimer(this);
  hintTimer->setInterval(10000);
  connect(hintTimer, SIGNAL(timeout()), this, SLOT(hintAvailableMoves()));

  // init components
  GameStock::init();

  toolset = new ToolSet();

  gameBonus = new GameBonus();

  setSceneRect(0,0, WIDTH, HEIGHT);

  // set background
  gameBackground = new GameBackground();
  setBackgroundBrush(Qt::black);

  setDefaultGameCursor();

  // update max level for current pack
  max_level = gameProfile->levelPackCount(gameProfile->currentLevelPack());

  // very first initialization
  initGame();
}
Exemplo n.º 9
0
/**
 * 解析配置文件, 初始化 index_lib内部的各个模块
 *
 * @param  config  xml的配置节点。  内部的子节点包括了 索引的各个配置项
 *         样例:
 *         <indexLib>
 *            <profile  path="/dir" />
 *            <index    path="/dir" />
 *            <idDict   path="/dir" />
 *            <provcity path="/dir" />
 *         </indexLib>
 *
 * @return  0: success ;   -1: 程序处理失败
 */
int init( mxml_node_t * config )
{
    mxml_node_t  * modulesNode  = NULL;
    mxml_node_t  * indexLibNode = NULL;               // index_lib的根节点
    mxml_node_t  * profileNode  = NULL;               // profile配置节点
    mxml_node_t  * indexNode    = NULL;               // index配置节点
    mxml_node_t  * idDictNode   = NULL;               // nid->docId 字典及deletemap节点
    mxml_node_t  * provcityNode = NULL;               // 行政区划表配置节点
    mxml_node_t  * add2modNode  = NULL;               // add转modify配置节点
    bool           syncFlag     = true;
    bool           exportFlag   = false;

    modulesNode  = mxmlFindElement(config, config, "modules", NULL, NULL, MXML_DESCEND);
    if ( modulesNode == NULL || modulesNode->parent != config )
    {
        TERR("can't find modules's node");
        return -1;
    }

    indexLibNode = mxmlFindElement(modulesNode, modulesNode, "indexLib", NULL, NULL, MXML_DESCEND);
    // 检查节点有效性
    if ( indexLibNode == NULL || indexLibNode->parent != modulesNode )
    {
        TERR("can't find indexLib's node");
        return -1;
    }

    // 检查增量持久化配置
    const char * syncStr = mxmlElementGetAttr(indexLibNode, "sync" );
    if (syncStr && strcasecmp(syncStr, "true") == 0) {
        syncFlag = true;
    }
    else {
        syncFlag = false;
    }

    // 检查mmap_lock配置
    const char * mLockStr = mxmlElementGetAttr(indexLibNode, "mmap_lock" );
    if (mLockStr && strcasecmp(mLockStr, "true") == 0) {
        struct rlimit sysLimit;
        if (getrlimit(RLIMIT_MEMLOCK, &sysLimit) == 0) {
            if ((sysLimit.rlim_cur==RLIM_INFINITY) &&
                    (sysLimit.rlim_max==RLIM_INFINITY))
            {
                IndexConfigParams::getInstance()->setMemLock();
            }
            else {
                TWARN("please unlimited max locked memory to enable mmap_lock");
            }
        }
        else {
            TWARN("get RLIMIT_MEMLOCK size failed, disable mmap_lock");
        }
    }

    // 关闭时是否导出倒排索引
    const char * et = mxmlElementGetAttr(indexLibNode, "export" );
    if (et && strcasecmp(et, "true") == 0) {
        exportFlag = true;
    }

    // 获取配置节点
    profileNode  = mxmlFindElement(indexLibNode, indexLibNode, "profile",  NULL, NULL, MXML_DESCEND);
    indexNode    = mxmlFindElement(indexLibNode, indexLibNode, "index",    NULL, NULL, MXML_DESCEND);
    idDictNode   = mxmlFindElement(indexLibNode, indexLibNode, "idDict",   NULL, NULL, MXML_DESCEND);
    provcityNode = mxmlFindElement(indexLibNode, indexLibNode, "provcity", NULL, NULL, MXML_DESCEND);
    add2modNode  = mxmlFindElement(indexLibNode, indexLibNode, "update_add2Modify", NULL, NULL, MXML_DESCEND);

    // 检查节点有效性
    if ( profileNode == NULL || profileNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node profile");
        return -1;
    }

    if ( indexNode == NULL || indexNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node index");
        return -1;
    }

    if ( idDictNode == NULL || idDictNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node idDict");
        return -1;
    }

    if ( provcityNode == NULL || provcityNode->parent != indexLibNode )
    {
        TERR("can't find indexLib's child node provcity");
        return -1;
    }

    int32_t inc_max_num = 0;
    const char * inc_max_num_str = mxmlElementGetAttr(indexNode, "inc_max_num" );
    if ( inc_max_num_str ) {
        inc_max_num = atol(inc_max_num_str);
    }

    // 开始 初始化 各个模块
    if ( initProfile(   mxmlElementGetAttr(profileNode,  "path" ), syncFlag, false ) )  return -1;
    if ( initIdDict (   mxmlElementGetAttr(idDictNode,   "path" ), syncFlag ) )  return -1;
    if ( initFullIndex( mxmlElementGetAttr(indexNode,    "path" ) ) )  return -1;
    if ( initIncIndex ( mxmlElementGetAttr(indexNode,    "path" ), syncFlag, exportFlag, inc_max_num) )  return -1;
    if ( initProvCity ( mxmlElementGetAttr(provcityNode, "path" ) ) )  return -1;
    if ( initIncManager( add2modNode ) )                               return -1;

    return 0;
}