Exemplo n.º 1
0
int main(int argc, char const *argv[])
{
	std::fstream f;
	f.open("test.txt");
	if(!f)
		std::cout << "open file fail" << std::endl;;

	JobList job;
	ProcessList process;
	PCB cur_process;
	unsigned int time = 0;

	job.init(f);
	while(1)
	{
		job.schedule(process,time);
		if(process.schedule(cur_process))
		{
			cur_process.running(time);
			std::cout << "running" << std::endl;
		}
		else
		{
			std::cout << "no running" << std::endl;
		}
		time++;
	}
	f.close();
	return 0;
}
Exemplo n.º 2
0
int main() {
  read_input();

  cout << "Initial: " << evaluate_jobs(jobs) << '\n';
  sort(jobs.begin(), jobs.end(), diff);
  cout << "Non-optimal: " << evaluate_jobs(jobs) << '\n';
  sort(jobs.begin(), jobs.end(), ratio);
  cout << "Optimal: " << evaluate_jobs(jobs) << '\n';
  return 0;  
}
Exemplo n.º 3
0
void read_input() {
  freopen("jobs.txt", "r", stdin);
  cin >> num_jobs;
  jobs.clear();

  for (int idx = 0; idx < num_jobs; ++idx) {
    int weight, length;
    cin >> weight >> length;
    jobs.push_back(make_pair(weight, length));
  }
  fclose(stdin);
}
Exemplo n.º 4
0
void WalkParameterWidget::onSendRequested(string text)
{
    debug << "sending" << endl;
    JobList jobs;
    WalkParameters parameters;
    
    stringstream ss(text);
    ss >> parameters;
    jobs.addMotionJob(new WalkParametersJob(parameters));
    *nuio << jobs;
    
    debug << parameters;
}
Exemplo n.º 5
0
void NUPlatform::process(JobList* jobs, NUIO* m_io)
{
    static list<Job*>::iterator it;     // the iterator over the jobs
    for (it = jobs->camera_begin(); it != jobs->camera_end();)
    {
        //debug  << "NUPlatform::Process - Processing Job" << endl;
        if ((*it)->getID() == Job::CAMERA_CHANGE_SETTINGS)
        {   // process a camera settings job
            CameraSettings settings;
            static ChangeCameraSettingsJob* job;
            job = (ChangeCameraSettingsJob*) (*it);
            settings = job->getSettings();
            #if DEBUG_NUPLATFORM_VERBOSITY > 4
                debug << "NUPlatform::process(): Processing a camera job." << endl;
            #endif
            
            if( settings.p_exposure.get() == 0 &&
                settings.p_contrast.get() == 0 &&
                settings.p_gain.get()     == 0 )
            {
                #if DEBUG_NUPLATFORM_VERBOSITY > 4
                    debug << "NUPlatform::Process - Send CAMERASETTINGS Request Recieved: " << endl;
                #endif
                JobList toSendList;
                ChangeCameraSettingsJob newJob(m_camera->getSettings());
                #if DEBUG_NUPLATFORM_VERBOSITY > 4
                    debug << "About to send: " << m_camera->getSettings();
                #endif
                toSendList.addCameraJob(&newJob);
                (*m_io) << toSendList;
                toSendList.clear();
            }
            else
            {   
                m_camera->setSettings(settings);
            }
            it = jobs->removeCameraJob(it);
        }
        else 
        {
            ++it;
        }

    }
    
}
Exemplo n.º 6
0
/// Generates a list of strings containing the input for each job.  The preview
/// flag determines if long input (such as external charges) is truncated.
QStringList InputDialog::generateInputJobStrings(JobList const& jobs, bool preview) 
{
   QStringList jobStrings;
   for (int i = 0; i < jobs.count(); ++i) {
       jobStrings << jobs[i]->format(preview);
   }

   return jobStrings;
}
Exemplo n.º 7
0
    static void delete_jobs(JobList& list)
    {
        for (each<JobList> i = list; i; ++i)
        {
            if (i->m_owned)
                delete i->m_job;
        }
 
        list.clear();
    }
Exemplo n.º 8
0
LL evaluate_jobs(const JobList& jobs) {
  int num_jobs = jobs.size();
  LL sum_lengths = 0;
  LL weighted_sum = 0;
  for (int idx = 0; idx < num_jobs; ++idx) {
    sum_lengths += jobs[idx].second;
    weighted_sum += jobs[idx].first * sum_lengths;
  }
  return weighted_sum;
}
Exemplo n.º 9
0
bool Job::updateJobStatuses( JobList jobs, const QString & jobStatus, bool resetTasks, bool restartHosts )
{
	if( jobs.isEmpty() )
		return false;

	QString keys = jobs.keyString();

	Database::current()->beginTransaction();

	if( restartHosts ){
		// Update each of the hosts that were working on the job
		if( !Database::current()->exec("UPDATE HostStatus SET slaveStatus = 'starting' WHERE fkeyJob IN(" + keys + ");").isActive() ) {
			Database::current()->rollbackTransaction();
			return false;
		}
	}

	if( resetTasks ) {
		foreach( Job j, jobs ) {
			JobDepList jdl = JobDep::recordsByJob(j);
			JobTaskList jtl = j.jobTasks().filter("status", "cancelled",  /*keepMatches*/ false);
			bool isSoftDep = false;
			foreach(JobDep jd, jdl){
				if( jd.depType() == 2 ) {
					isSoftDep = true;
					break;
				}
			}

			if( !isSoftDep )
				jtl.setStatuses("new");
			else
				jtl.setStatuses("holding");

			jtl.setColumnLiteral("fkeyjoboutput","NULL");
			if( j.packetType() != "preassigned" )
				jtl.setHosts(Host());
			jtl.commit();
		}
	}
Exemplo n.º 10
0
void JobHistoryView::setJobs( JobList jobs )
{
	setHistory(jobs.jobHistories());
	mJobs = jobs;
}
Exemplo n.º 11
0
int main( int argc, char * argv[] )
{
	int result=0;

#ifdef Q_OS_WIN
	hMutex = CreateMutex( NULL, true, L"FreezerSingleProcessMutex");
	if (hMutex == NULL) {
		LOG_5( "Error: Couldn't create mutex, exiting" );
		return false;
	}
	if( GetLastError() == ERROR_ALREADY_EXISTS ) {
		LOG_5( "Error: Another process owns the mutex, exiting" );
		QList<int> pids;
		if( pidsByName( "freezer.exe", &pids ) ) {
			int otherProcessId = pids[0];
			if( otherProcessId == processID() ) {
				if( pids.size() < 2 )
					return false;
				otherProcessId = pids[1];
			}
			LOG_5( "Trying to find window with process pid of " + QString::number( otherProcessId ) );
			EnumWindows( AFEnumWindowsProc, LPARAM(otherProcessId) );
		}
		return false;
	}

	QLibrary excdll( "exchndl.dll" );
	if( !excdll.load() ) {
		qWarning( excdll.errorString().toLatin1().constData() );
	}
	disableWindowsErrorReporting( "assburner.exe" );

#endif

    signal(SIGSEGV, oops_handler);
    signal(SIGABRT, oops_handler);
	QApplication a(argc, argv);

    if( !initConfig( "freezer.ini" ) ) {
#ifndef Q_OS_WIN
        // Fallback if the config file does not exist in the current folder
        if( !initConfig( "/etc/ab/freezer.ini" ) )
#endif
        return -1;
    }

#ifdef Q_OS_WIN
	QString cp = "h:/public/" + getUserName() + "/Blur";
	if( !QDir( cp ).exists() )
		cp = "C:/Documents and Settings/" + getUserName();
	initUserConfig( cp + "/freezer.ini" );
#else
	initUserConfig( QDir::homePath() + "/.freezer" );
#endif

    initStone( argc, argv );
    classes_loader();
    initStoneGui();
	{
		JobList showJobs;
		bool showTime = false;
        QString currentView;
        QStringList loadViewFiles;

		for( int i = 1; i<argc; i++ ){
			QString arg( argv[i] );
			if( arg == "-h" || arg == "--help" )
			{
				LOG_1( QString("Freezer v") + VERSION );
				LOG_1( "Options:" );
				LOG_1( "-current-render" );
				LOG_1( "\tShow the current job that is rendering on this machine\n" );
				LOG_1( "-show-time" );
				LOG_1( "\tOutputs summary of time executed for all sql statement at program close\n" );
				LOG_1( "-user USER" );
				LOG_1( "\tSet the logged in user to USER: Requires Admin Privs" );
				LOG_1( "-current-view VIEWNAME" );
				LOG_1( "\tMake VIEWNAME the active view, once they are all loaded" );
				LOG_1( "-load-view FILE" );
				LOG_1( "\tRead a saved view config from FILE" );
				LOG_1( stoneOptionsHelp() );
				return 0;
			}
			else if( arg.endsWith("-show-time") )
				showTime = true;
			else if( arg.endsWith( "-current-render" ) ) {
				showJobs = Host::currentHost().activeAssignments().jobs();
			}
			else if( arg.endsWith("-user") && (i+1 < argc) ) {
				QString impersonate( argv[++i] );
				if( User::hasPerms( "User", true ) ) // If you can edit users, you can login as anyone
					User::setCurrentUser( impersonate );
			}
            else if( arg.endsWith("-current-view") && (i+1 < argc) ) {
				currentView = QString( argv[++i] );
            }
            else if( arg.endsWith("-load-view") && (i+1 < argc) ) {
                loadViewFiles << QString(argv[++i]);
            }
		}

		// Share the database across threads, each with their own connection
		FreezerCore::setDatabaseForThread( classesDb(), Connection::createFromIni( config(), "Database" ) );
		
		{
            loadPythonPlugins();
			MainWindow m;
			IniConfig & cfg = userConfig();
			cfg.pushSection( "MainWindow" );
			QStringList fg = cfg.readString( "FrameGeometry", "" ).split(',');
			cfg.popSection();
			if( fg.size()==4 ) {
				m.resize( QSize( fg[2].toInt(), fg[3].toInt() ) );
				m.move( QPoint( fg[0].toInt(), fg[1].toInt() ) );
			}
			if( showJobs.size() )
				m.jobPage()->setJobList( showJobs );
            foreach( QString viewFile, loadViewFiles )
                m.loadViewFromFile( viewFile );
            if( !currentView.isEmpty() )
                m.setCurrentView( currentView );
			m.show();
			result = a.exec();
			if( showTime ){
				Database * tm = Database::current();
				LOG_5( 			"                  Sql Time Elapsed" );
				LOG_5(			"|   Select  |   Update  |  Insert  |  Delete  |  Total  |" );
				LOG_5( 			"-----------------------------------------------" );
				LOG_5( QString(	"|     %1    |     %2    |    %3    |    %4    |    %5   |\n")
					.arg( tm->elapsedSqlTime( Table::SqlSelect ) )
					.arg( tm->elapsedSqlTime( Table::SqlUpdate ) )
					.arg( tm->elapsedSqlTime( Table::SqlInsert ) )
					.arg( tm->elapsedSqlTime( Table::SqlDelete ) )
					.arg( tm->elapsedSqlTime() )
				);
				LOG_5( 			"                  Index Time Elapsed" );
				LOG_5(			"|   Added  |   Updated  |  Incoming  |  Deleted  |  Search  |  Total  |" );
				LOG_5( 			"-----------------------------------------------" );
				LOG_5( QString(	"|     %1     |     %2    |    %3    |    %4   |    %5    |   %6    |\n")
					.arg( tm->elapsedIndexTime( Table::IndexAdded ) )
					.arg( tm->elapsedIndexTime( Table::IndexUpdated ) )
					.arg( tm->elapsedIndexTime( Table::IndexIncoming ) )
					.arg( tm->elapsedIndexTime( Table::IndexRemoved ) )
					.arg( tm->elapsedIndexTime( Table::IndexSearch ) )
					.arg( tm->elapsedIndexTime() )
				);
				tm->printStats();
			}
		}
	}
	shutdown();
#ifdef Q_OS_WIN
	CloseHandle( hMutex );
#endif
	return result;
}
Exemplo n.º 12
0
/*! @brief Jobs created by the WalkOptimiserBehaviour are added here.
 
    The behaviour has 4 states:
        1. Initial where we are just waiting for the simulator to go into 'playing'
        3. MeasureCost where we actually perform the measurement of the cost
        5. MeasureRobust where we actually perform the measurement of the robustness
        6. Teleport where the robot is teleported back to its initial position
 
    @param joblist the list of jobs to which job(s) will be added
 */
void WalkOptimiserBehaviour::process(JobList& joblist)
{
    static int fallencount = 0;
    static vector<float> speed(3,0);
    static WalkJob* job = new WalkJob(speed);
    
    if (m_data == NULL || m_actions == NULL)
        return;

    m_previous_state = m_state;
    m_previous_time = m_current_time;
    m_current_time = m_data->CurrentTime;
    
    if (m_state == Initial)
    {   // In the initial state we wait until the simulator puts the game in 'playing' and I have time to score a goal!
        if (m_data->CurrentTime > 15000)
        {
            m_state = MeasureCost;
            teleport();
        }
    }
    else if (m_state == Teleport)
    {   // In the teleport state we wait until the robot has stopped
        // We then respawn, and then wait another 0.5s before proceeding to the next state
        
        // handle the deacceleration (now done in the walk engine itself)
        m_target_speed = 0;
        
        // wait until the robot comes to rest
        static vector<float> speed(3,0);
        static double stoppedtime = 0;
        static bool stopped = false;
        m_walk->getCurrentSpeed(speed);
        if (stopped == false && speed[0] == 0)
        {
            stoppedtime = m_current_time;
            stopped = true;
        }
            
        // handle the respawn call (being careful to only call it once because it really slows webots down)
        static bool respawn_called = false;
        if (respawn_called == false && stopped == true && (m_current_time - stoppedtime) > 500)
        {
            respawn();
            respawn_called = true;
        }
        
        // handle the timely progress to the next state
        if (respawn_called == true && stopped == true && (m_current_time - stoppedtime) > 1000)
        {
            m_state = m_next_state;
            m_target_speed = 0;
            fallencount = 0;
            respawn_called = false;
            stopped = false;
            if (m_trial_out_of_field == false)
            {
                if (m_state == MeasureCost)
                    startCostTrial();
                else if (m_state == MeasureRobust)
                    startRobustTrial();
            }
            else
                m_trial_out_of_field = false;
        }
    }
    else if (m_data->isFallen())
    {   // In the fallen state, we wait to make sure we are actually fallen, and then finish the current trial
        fallencount++;
        if (fallencount > 9)
        {
            if (m_state == MeasureCost)
                finishMeasureCost();
            else if (m_state == MeasureRobust)
                finishMeasureRobust();
        }
    }
    else 
    {
        fallencount = 0;                // reset the fallen count when we are not falling
        
        // handle accelerating walks up to maximum speed (now done in the walk engine itself)
        m_target_speed = m_walk_parameters[0];
        
        // look for terminating distances while measuring walk performance
        static vector<float> gps(3,0);
        m_data->getGPSValues(gps);
        float totaldistance = sqrt(pow(gps[0] - m_respawn_x,2) + pow(gps[1] - m_respawn_y,2));
        if (m_state == MeasureCost)
        {
            if (totaldistance > 300.0)      // if walked more than 300cm begin to stop the robot
            {
                m_target_speed = 0;
                static vector<float> speeds(3,0);
                m_walk->getCurrentSpeed(speeds);
                if (speeds[0] == 0)         // once the robot has stopped finish the cost measurement
                    finishMeasureCost();
            }
        }
        else if (m_state == MeasureRobust)
        {
            if (totaldistance > 450.0)
            {
                m_trial_out_of_field = true;
                teleport();
            }
        }
    }
    speed[0] = m_target_speed;
    job->setSpeed(speed);
    joblist.addMotionJob(job);
}