コード例 #1
0
ファイル: daojishi.c プロジェクト: loversmile/mytest
/* nowdat, setday */
int func(struct ymd *nowday, struct ymd *setday)
{
    int y = nowday->year;
    int m = nowday->month;
    int d = nowday->day;
    int yy = setday->year;
    int mm = setday->month;
    int dd = setday->day;
    int returnday = 0;
    if( (y > yy) || (y == yy && m > mm) || (y == yy && m == mm && d > dd) )
    {
        if (y > yy)
            returnday = hasR(y, yy) + 365 *(y - yy -1) + toEnd(yy, mm, dd) + toStart(y, m, d);
        else if (y == yy)
            returnday = toEnd(yy, mm, dd) - toEnd(y, m, d);
    } 
    else if ( y == yy && m == mm && d == dd )
    {
        return 0;
    }
    else
    {
        if (yy > y)
            returnday = hasR(yy, y) + 365 *(yy - y -1) + toEnd(y ,m, d) + toStart(yy, mm, dd);
        else if (y == yy)
            returnday = toEnd(y, m, d) - toEnd(yy, mm, dd);
    }
    return returnday;
}
コード例 #2
0
ファイル: utf8_16.cpp プロジェクト: berserkerkira/NotePlus
// Go to the next byte.
void Utf8_Iter::operator++()
{
	switch (m_eState)
    {
        case eStart:
            if (*m_pRead < 0x80) {
                m_nCur = *m_pRead;
                toStart();
            } else if (*m_pRead < 0xE0) {
                m_nCur = static_cast<utf16>((0x1F & *m_pRead) << 6);
                m_eState = e2Bytes_Byte2;
            } else {
                m_nCur = static_cast<utf16>((0xF & *m_pRead) << 12);
                m_eState = e3Bytes_Byte2;
            }
            break;
        case e2Bytes_Byte2:
        case e3Bytes_Byte3:
            m_nCur |= static_cast<utf8>(0x3F & *m_pRead);
            toStart();
            break;
        case e3Bytes_Byte2:
            m_nCur |= static_cast<utf16>((0x3F & *m_pRead) << 6);
            m_eState = e3Bytes_Byte3;
            break;
	}
	++m_pRead;
}
コード例 #3
0
ファイル: daojishi.c プロジェクト: loversmile/mytest
/* Not include the day*/
int toEnd(int y, int m, int d)
{
    if (isR(y))
    {
        printf( "toEnd %d\n", (366 - toStart(y, m, d)));
        return (366 - toStart(y, m, d));
    }
    printf( "toEnd %d\n", (365 - toStart(y, m, d)));
    return (365 - toStart(y, m, d));
}
コード例 #4
0
//@njz
//GAConjProblemForORGroupSolver::GAConjProblemForORGroupSolver( const OneRelatorGroup& group , const Word& W1 , const Word& W2 , bool createFile = true , bool cp = true ) : 
GAConjProblemForORGroupSolver::GAConjProblemForORGroupSolver( const OneRelatorGroup& group , const Word& W1 , const Word& W2 , bool createFile , bool cp ) : 
//
  theGroup( group ),
  conjProblem( cp ),
  fitnessRate( 0 )
{
  if( createFile ) { 
    file = new File;
    deleteFile = true;
  }
  else {
    file = 0;
    deleteFile = false;
  }

  numGenes = 50;
  genes = new GACPforORGSolverGene*[numGenes];
  for( int i=0 ; i<numGenes ; ++i ) genes[i] = 0;
  
  //create two genes
  newGene[0] = new GACPforORGSolverGene( theGroup , Word() , Word() );
  newGene[1] = new GACPforORGSolverGene( theGroup , Word() , Word() );

  if( file )
    if( conjProblem )
      *file << "This genetic algorithm tries to determine whether given words are conjugate." << endl << endl;
    else
      *file << "This genetic algorithm tries to determine whether the given word is trivial." << endl << endl;

  toStart( W1 , W2 );
}
コード例 #5
0
ファイル: ServiceAbstract.cpp プロジェクト: edenduthie/rtft1
void ServiceAbstract::open(ServiceParamsPtr& params, int ftype, QoSManagerInterface* qosManager) throw (ServiceException&) {
    ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock);
    toStarting();
    m_qosManager = qosManager;
    open_i(params, ftype);
    toStart();
}
コード例 #6
0
void GAConjProblemForORGroupSolver::checkImprovementTime( )
{
  if( lastImprovement >= 40*numGenes ) {
    int g = selectGene( );
    if( file )
      *file << "The algorithm does not seem to be making any progress. "
	    << "Restarting the algorithm." << endl << endl;
    toStart( genes[g]->getWord1( ) , genes[g]->getWord2( ) );
    theIter2 = 0;
    lastImprovement = 0;
    ++fitnessRate;
  }
}
コード例 #7
0
ファイル: gotime.c プロジェクト: loversmile/mytest
/* y is now, yy is the set day */
int func(int y, int m, int d, int yy, int mm, int dd)
{
    int returnday = 0;
    if( (y > yy) || (y == yy && m > mm) || (y == yy && m == mm && d > dd) )
    {
        if (y > yy)
            returnday = hasR(y, yy) + 365 *(y - yy -1) + toEnd(yy, mm, dd) + toStart(y, m, d);
        else if (y == yy)
            returnday = toEnd(yy, mm, dd) - toEnd(y, m, d);
    } 
    else if ( y == yy && m == mm && d == dd )
    {
        return 0;
    }
    else
    {
        if (yy > y)
            returnday = hasR(yy, y) + 365 *(yy - y -1) + toEnd(y ,m, d) + toStart(yy, mm, dd);
        else if (y == yy)
            returnday = toEnd(y, m, d) - toEnd(yy, mm, dd);
    }
    return returnday;
}
コード例 #8
0
GAConjProblemForORGroupSolver::GAConjProblemForORGroupSolver( const OneRelatorGroup& group , const Word& W1 , const Word& W2 , File* f ) : 
  theGroup( group ),
  file( f ),
  deleteFile( false ),
  fitnessRate( 0 ),
  numGenes( 50 )
{
  genes = new GACPforORGSolverGene*[numGenes];
  for( int i=0 ; i<numGenes ; ++i ) genes[i] = 0;
  
  // create two helper genes, they are used for reproduction
  newGene[0] = new GACPforORGSolverGene( theGroup , Word() , Word() );
  newGene[1] = new GACPforORGSolverGene( theGroup , Word() , Word() );

  toStart( W1 , W2 );
}
コード例 #9
0
         dialog::RESULT fileSelect::run()
         {
            if (!init(size_))
               {
                  return dialog::R_NCREAT;
               }

            refresh();

            // Handle keyboard.

            keyMapping::KEYLABEL label;

            bool cont    = true;

            while (cont)
               {
                  label = handleKeyboard();

                  switch (label)
                     {
                     case keyMapping::K_HELP:
                        {
                           if (showHelp() == dialog::R_RESIZE)
                              {
                                 // Resized window.
                                 return dialog::R_RESIZE;
                              }
                           break;
                        }
                     case keyMapping::K_QUIT:
                        {
                           cont = false;
                           break;
                        }
                     case keyMapping::K_DOWN:
                        {
                           moveDown();
                           refresh();
                           break;
                        }
                     case keyMapping::K_UP:
                        {
                           moveUp();
                           refresh();
                           break;
                        }
                     case keyMapping::K_LIST_START:
                        {
                           toStart();
                           refresh();
                           break;
                        }
                     case keyMapping::K_LIST_END:
                        {
                           toEnd();
                           refresh();
                           break;
                        }
                     case keyMapping::K_MARK:
                        {
                           handleMark();
                           moveDown();
                           refresh();
                           break;
                        }
                     case keyMapping::K_SELECT:
                        {
                           pressed_select_key_ = true;
                           cont                = false;
                           break;
                        }
                     case keyMapping::K_MARK_ALL:
                        {
                           handleMarkAll();
                           break;
                        }
                     case keyMapping::K_RESIZE:
                        {
                           // Close this window, and make the parent
                           // resize its window.
                           return dialog::R_RESIZE;
                           break;
                        }
                     default:
                        {
                           refresh();
                           break;
                        }
                     }
               }

            return dialog::R_QUIT;
         }
コード例 #10
0
ファイル: SthenoCore.cpp プロジェクト: edenduthie/rtft1
void SthenoCore::open(ACE_ARGV& args) throw (RuntimeException&) {
    ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock);

    m_reservationFlag = false;
    m_runNO = 0; //no run
    m_testNO = 0; //no test
    m_trace = true;
    m_maxServicesQoS = 2;
    //m_runtimeQoS = 950000;
    //absolute
    // dont need this
    m_runtimeQoS = RUNTIME_DEFAULT_QOS; //5000;
    m_runtimePeriod = CPUReservation::DEFAULT_PERIOD;

    //signal handling
    ACE_Sig_Action no_sigpipe((ACE_SignalHandler) SIG_IGN);
    ACE_Sig_Action original_action;
    no_sigpipe.register_action(SIGPIPE, &original_action);


    static const ACE_TCHAR options[] = ACE_TEXT("::");
    const char* prefix = "\0";
    ACE_Get_Opt cmd_opts(args.argc(), args.argv(), options);
    int option;
    if (cmd_opts.long_option
            (ACE_TEXT("prefix"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("run"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("test"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("reservation"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("maxservices"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("runtimeqos"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("runtimeqosperiod"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }
    printf("AGRS=%d\n", args.argc());

    while ((option = cmd_opts()) != EOF)
        switch (option) {
            case 0:
            {
                //long_option
                const char *op = cmd_opts.long_option();
                printf("LONG=%s\n", cmd_opts.opt_arg());
                if (ACE_OS::strcmp("prefix", op) == 0) {
                    prefix = cmd_opts.opt_arg();
                    printf("Prefix=%s\n", prefix);
                    break;
                }
                if (ACE_OS::strcmp("run", op) == 0) {
                    m_runNO = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("RunNo=%d %s\n", m_runNO, cmd_opts.opt_arg());
                    break;
                }

                if (ACE_OS::strcmp("test", op) == 0) {
                    m_testNO = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("TestNo=%d %s\n", m_testNO, cmd_opts.opt_arg());
                    break;
                }
                if (ACE_OS::strcmp("reservation", op) == 0) {
                    if (strcasecmp(cmd_opts.opt_arg(), "true") == 0) {
                        m_reservationFlag = true;
                    }
                    break;
                }
                if (ACE_OS::strcmp("maxservices", op) == 0) {
                    m_maxServicesQoS = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    break;
                }

                if (ACE_OS::strcmp("runtimeqos", op) == 0) {
                    m_runtimeQoS = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("runtimeqos=%d %s\n", m_runtimeQoS, cmd_opts.opt_arg());
                    break;
                }

                if (ACE_OS::strcmp("runtimeqosperiod", op) == 0) {
                    m_runtimePeriod = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("runtimeqosPeriod=%d %s\n", m_runtimeQoS, cmd_opts.opt_arg());
                    break;
                }
                break;
            }
            case ':':
            {
                ACE_ERROR
                        ((LM_ERROR, ACE_TEXT("-%c requires an argument\n"),
                        cmd_opts.opt_opt()));
                throw RuntimeException(RuntimeException::INVALID_ARGS);
            }
            default:
            {
            }
        }


    m_p2pQoS = P2P_DEFAULT_QOS; //5000;
    m_servicesQoS = SERVICE_MANAGER_DEFAULT_QOS; //5000;
    //total=75K
    //m_perServicesQoS = 25000;//25000;
    /*m_p2pQoS = m_runtimeQoS * 0.2;    
    m_servicesQoS = m_runtimeQoS * 0.8;        
    m_perServicesQoS = m_servicesQoS / m_maxServicesQoS;*/

    //services 100+50 = 150k
    //core 10k
    //p2p 125k
    //

    stringstream statFile;
    stringstream traceFile;
    stringstream debugFile;
    statFile << "stat_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log";
    traceFile << "trace_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log";
    debugFile << "debug_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log";
    initLogging(statFile.str().c_str(), traceFile.str().c_str(), debugFile.str().c_str());
    initRuntimeQoS(args);
    UUIDPtr runtimeUUID;
    getUUID(runtimeUUID);
    String runtimeDomainPath = "";
    m_runtimeQoSManager = this->getQoSManagerInterface(runtimeDomainPath, RUNTIME_DEFAULT_QOS, m_runtimePeriod, false);
    /*if(m_signalHandler.open()!=0){
        throw RuntimeException(RuntimeException::INVALID_OVERLAY);
    }*/

    try {
        QoSManagerInterface* qosManager = 0;
        if (m_reservationFlag) {
            //String p2pPath = "p2p";
            //qosManager = this->getQoSManagerInterface(p2pPath, m_p2pQoS, m_runtimePeriod);
            qosManager = m_runtimeQoSManager;
        }
        getOverlay()->open(qosManager);
        if (m_reservationFlag) {
            //String servicesPath = "services";
            //m_serviceQosManager = this->getQoSManagerInterface(servicesPath, m_servicesQoS, m_runtimePeriod);            
            m_serviceQosManager = m_runtimeQoSManager;
        }

    } catch (OverlayException& ex) {
        throw RuntimeException(RuntimeException::INVALID_OVERLAY);
    } catch (RuntimeException& runtimeEx) {
        throw RuntimeException(RuntimeException::INVALID_OVERLAY);
    }
    toStart();
    if (trace()) {
        TraceRuntimeSingleton::instance()->logRuntimeOpen(this->m_peerID);
    }
}
コード例 #11
0
ファイル: startscene.cpp プロジェクト: dotkrnl/dotFive
void StartScene::startClicked(void)
{
    m_current = WAITING;
    updateStatus();
    emit toStart();
}
コード例 #12
0
ファイル: ServiceAbstract.cpp プロジェクト: edenduthie/rtft1
void ServiceAbstract::resume() throw (ServiceException&) {
    ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock);
    toStarting();
    resume_i();
    toStart();
}
コード例 #13
0
ファイル: pathfinder.cpp プロジェクト: astrellon/GPP
	bool Pathfinder::search(const Vector2i &start, Vector2i end, NodePath &path, Map *map, const GameObject *forObj)
	{
		if (!map || 
			start.x < 0 || start.x >= map->getMapWidth() ||
			start.y < 0 || start.y >= map->getMapHeight() ||
			end.x < 0 || end.x >= map->getMapWidth() ||
			end.y < 0 || end.y >= map->getMapHeight() ||
			(start.x == end.x && start.y == end.y))
		{
			return false;
		}

		mMap = map;
		int startGroup = map->mMapData[start.x][start.y].group;
		int endGroup = map->mMapData[end.x][end.y].group;
		if(startGroup != endGroup)
		{
			mMap = NULL;
			return false;
		}

		if (!map->isValidGridLocation(end.x, end.y, forObj))
		{
			// Move back towards the start position until we do find a passable location.
			Engine *engine = Engine::getEngine();
			Vector2f fstart(start);
			Vector2f fend(end);
			Vector2f toStart(fend.sub(fstart));
			int numSteps = static_cast<int>(toStart.length() * 2.0f);
			toStart.normalise();
			toStart.scale(0.5f);

			for (int step = 0; step < numSteps; step++)
			{
				fend = fend.sub(toStart);
				Vector2i grid(fend);
				if (map->isValidGridLocation(grid.x, grid.y, forObj))
				{
					break;
				}
			}

			end.x = round(fend.x);
			end.y = round(fend.y);

			endGroup = map->mMapData[end.x][end.y].group;
			if(startGroup != endGroup)
			{
				mMap = NULL;
				return false;
			}
		}

		mOpenList.clear();
		mClosedList.clear();

		mNodeUseCounter++;

		mOpenList.push_back(&map->mMapData[start.x][start.y]);

		AStarNode *endNode = &map->mMapData[end.x][end.y];
		endNode->parent = NULL;

		while(!mOpenList.empty())
		{
			AStarNode *node = mOpenList.front();
			if(node->useCounter < mNodeUseCounter)
			{
				node->g = 0;
				node->useCounter = mNodeUseCounter;
				node->parent = NULL;
			}
		
			if (node == endNode)
			{
				// Complete
				getPath(node, path);
				mMap = NULL;
				return true;
			}
			else
			{
				mOpenList.erase(mOpenList.begin());
				mClosedList.push_back(node);

				mNeighbors.clear();
				getNeighbors(node->gridPosition, forObj);
				for(auto iter = mNeighbors.begin(); iter != mNeighbors.end(); ++iter)
				{
					AStarNode *n = *iter;
					if (!Utils::listContains(mOpenList, n) &&
						!Utils::listContains(mClosedList, n))
					{
						if (n->useCounter < mNodeUseCounter)
						{
							n->g = 0;
							n->useCounter = mNodeUseCounter;
						}
						n->g += node->g;

						n->f = n->g + manhattanDistance(n->position, endNode->position);

						n->parent = node;
						mOpenList.push_back(n);
					}
				}

				mNeighbors.clear();
				sortAStarList(mOpenList);
			}
		}
		// NO PATH! D:
		mMap = NULL;
		return false;
	}
コード例 #14
0
bool GAConjProblemForORGroupSolver::tournament( GACPforORGSolverGene &gene )
{
  double newFit = gene.fitness( );

  // number of last iterations with conjecture
  // I do next iteration through 1000 iterations
  static int it = theIter1;

  if( newFit==0 ) {
    bestFit = 0;
    lastImprovement = 0;
    if( file )
    *file << "Generation " << theIter1 << ", best fitness " << bestFit << endl << endl;
    return false;
  }

  if( gene.getHasShorterWords( ) ) {
    if( file )
      *file << "Given words can be shortened." << endl << endl;
    toStart( gene.getWord1( ) , gene.getWord2( ) );
    theIter2 = 0;
    return true;
  }

  //Conjecture
  if( gene.getHasConjecture( ) && theIter1 - it>1000 ) {
    Word conjWord = gene.getConjectureWord( );

    int nCheck = 1;
    if( checkedWords.bound(conjWord) )
      nCheck = checkedWords.valueOf( conjWord )+1;

    if( theIter1 - it > 1000*nCheck ) {
      checkedWords.bind( conjWord , nCheck );
      
      if( file ) {
	*file << "The algorithm will try to check whether ";
	theGroup.printWord( *file , conjWord );
	*file << " is trivial.";
	*file << endl << endl;
      }

      GAConjProblemForORGroupConjecture conjecture( theGroup , conjWord , file );
      bool conjResult = conjecture.isConj( 1000 , theIter1 );
      it = theIter1;

      if( conjResult ) {
	bestFit = 0;
	lastImprovement = 0;
	if( file ) {
	  *file << "The word is trivial." << endl << endl;
	  *file << "Generation " << theIter1 << ", best fitness " << bestFit << endl << endl;
	}
	return false;
      }

      if( file ) 
	*file << "The algorithm couldn't determine whether the word was trivial." << endl << endl;    
    }
  }
  
  // get random chromosome and compare it with the new one by roulette wheel
  int g = rnd1( numGenes );
  
  if( newFit<bestFit ) {
    delete genes[g];
    genes[g] = new GACPforORGSolverGene( gene );
    bestFit = newFit;
    lastImprovement = 0;
    if( file )
      *file << "Generation " << theIter1 << ", best fitness " << bestFit << endl << endl;
    return false;
  }
  
  if( !genes[g] )
    genes[g] = new GACPforORGSolverGene( gene );
  else {
    double prob1 = newFit, prob2 = genes[g]->fitness( );
    double min = ( prob1<prob2 ? prob1 : prob2 );
    if( min>5 ) { 
      prob1 -= min - 5;
      prob2 -= min - 5;
    }
    prob1 += fitnessRate;
    prob2 += fitnessRate;

    if( (roulette( prob1 , prob2 )==1 ) ) {
      delete genes[g];
      genes[g] = new GACPforORGSolverGene( gene );
    }
  }
  return false;
}
コード例 #15
0
void GAConjProblemForORGroupSolver::toStart( const Word& W1 , const Word& W2 )
{
  theWord1 = W1;
  theWord2 = W2;

  lastImprovement = 0;

  if( file ) {
    *file << "Run algorithm on words ";
    theGroup.printWord( *file , W1 );
    *file << " and ";
    theGroup.printWord( *file , W2 );
    *file << "." << endl << endl;
  }

  //1. try to reduce words in the given group (by the greedy algorithm)
  Word w1 = greedyReduce( theGroup , theWord1 );
  Word w2 = greedyReduce( theGroup , theWord2 );

  //2. if words are reducible, note about
  if( file && ( w1.length()<W1.length() || w2.length()<W2.length() ) ) {
    *file << "The length of at least one of the words can be reduced. "
	  << "We are going to continue to work with the shorter words: ";
    theGroup.printWord( *file , w1 );
    *file << " and ";
    theGroup.printWord( *file , w2 );
    *file << "." << endl << endl;
  }
  
  //3. first word must be shorter than second one
  if( w1.length()>w2.length() ) {
    Word tmp = w1;
    w1 = w2;
    w2 = tmp;
  }

  //4. remove all existing genes
  for( int i=0 ; i<numGenes ; ++i ) {
    if( genes[i] ) delete genes[i];
    genes[i] = 0;
  }

  //5. set first gene ( just one gene in the population at this time )
  genes[0] = new GACPforORGSolverGene( theGroup , w1 , w2 );
  
  //6. fast check
  genes[0]->check( );
  if( GACPforORGSolverGene( theGroup , w1 , w2 ).noConj( ) ) {
    if( file )
      if( conjProblem )
	*file << "Words are not conjugate because they are not conjugate in the abelian quotient." << endl << endl;
      else
	*file << "The word is not trivial because it is not trivial in the abelian quotient." << endl << endl;
    bestFit = NOCONJ;
    return;
  }

  //7. compute fitness of the first gene
  bool start;
  bestFit = genes[0]->fitness( );

  //8. if we got even more shorter words, then go to start with these
  if( genes[0]->getHasShorterWords( ) )
    toStart( genes[0]->getWord1( ) , genes[0]->getWord2( ) );
  else {
    if( file )
      *file << "Fitness = " << bestFit << endl << endl;
  }
}