const StepInfo* StepManager::getStep(step_id_type id) {
    const steps_type::const_iterator step = steps().find(id);
    if (step == steps().end()) {
        return NULL;
    }
    return step->second.get();
}
/**
 * \brief default main function for focusing
 */
void	FocusWork::main(astro::thread::Thread<FocusWork>& thread) {
	if (!complete()) {
		debug(LOG_ERR, DEBUG_LOG, 0,
			"FocusWork is not completely configured");
		focusingstatus(Focusing::FAILED);
		return;
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "starting focus process in [%d,%d]",
		min(), max());

	// prepare the set of focus items to base the focus computation on
	FocusItems	focusitems;

	// prepare 
	for (int step = 0; step < steps(); step++) {
		// find position
		unsigned short	position
			= min() + (step * (max() - min())) / (steps() - 1);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "next position: %hu", position);

		// move to this position
		moveto(position);

		// get an image
		focusingstatus(Focusing::MEASURING);
		ccd()->startExposure(exposure());
		usleep(1000000 * exposure().exposuretime());
		ccd()->wait();
		ImagePtr	image = ccd()->getImage();
		debug(LOG_DEBUG, DEBUG_LOG, 0, "got an image of size %s",
			image->size().toString().c_str());

		// evaluate the image
		double	value = (*evaluator())(image);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "evaluated to %f", value);

		// callback with the evaluated image
		callback(evaluator()->evaluated_image(), position, value);

		// add the information to a set
		focusitems.insert(FocusItem(position, value));
	}

	// now solve we need a suitable solver for the method
	int	targetposition = solver()->position(focusitems);
	if ((targetposition < min()) || (targetposition > max())) {
		std::string	msg = stringprintf(
			"could not find a focus position: %d", targetposition);
		debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str());
		focusingstatus(Focusing::FAILED);
		return;
	}

	// move to the final focus position
	focusingstatus(Focusing::MOVING);
	moveto(targetposition);
	focusingstatus(Focusing::FOCUSED);
}
MatchResult StepManager::stepMatches(const std::string &stepDescription) {
    MatchResult matchResult;
    for (steps_type::iterator iter = steps().begin(); iter != steps().end(); ++iter) {
        StepInfo *stepInfo = iter->second;
        SingleStepMatch currentMatch = stepInfo->matches(stepDescription);
        if (currentMatch) {
            matchResult.addMatch(currentMatch);
        }
    }
    return matchResult;
}
 const step_id_type getStepId(const std::string &stepMatcher) {
     step_id_type id = 0;
     for (steps_type::const_iterator i = steps().begin(); i != steps().end(); ++i) {
         StepInfo *stepInfo = i->second;
         if (stepInfo->regex.str() == stepMatcher) {
             id = stepInfo->id;
             break;
         }
     }
     return id;
 }
void
search_around (int x, int y, int step, int steps[])
{

  if (step < steps (x, y) || step == 0)
    {
      steps (x, y) = step;
      search_around (x - 1, y, step + 1, steps);
      search_around (x + 1, y, step + 1, steps);
      search_around (x, y - 1, step + 1, steps);
      search_around (x, y + 1, step + 1, steps);
    }
}
Exemple #6
0
 int jump(vector<int>& nums) {
     if(nums.size() == 1) return 0;
     if(nums.size() == 2) return 1;
     vector<int> steps(nums.size(), 0);
     for(int i = nums.size()-2; i >= 0; i --) {
     	//one step to the end
         if(nums[i] + i >= nums.size()-1) {
             steps[i] = 1;
         }
         //can't go further
         else if(nums[i] == 0) steps[i] = -1;
         else {
         	//find min in steps that i can reach
             for(int j = nums[i]; j >= 1; j --) {
                 if(steps[i+j] == -1) continue;
                 else if(steps[i+j] == 1) {
                     steps[i] = 2;
                     break;
                 }
                 else {
                     if(steps[i] == 0) steps[i] = steps[i+j]+1;
                     else steps[i] = min(steps[i],steps[i+j]+1);
                 }
             }
             if(steps[i] == 0) steps[i] = -1;
         }
     }
     return steps[0];
 }
Exemple #7
0
  std::string WorkflowJSON_Impl::string(bool includeHash) const
  {
    Json::Value clone(m_value);
    if (!includeHash){
      clone.removeMember("hash");
    }

    Json::Value steps(Json::arrayValue);
    for (const auto& step : m_steps){

      Json::Reader reader;
      Json::Value stepValue;
      bool parsingSuccessful = reader.parse(step.string(), stepValue);
      if (parsingSuccessful){
        steps.append(stepValue);
      }
    }
    clone["steps"] = steps;

    if (m_runOptions){
      Json::Reader reader;
      Json::Value options;
      bool parsingSuccessful = reader.parse(m_runOptions->string(), options);
      if (parsingSuccessful){
        clone["run_options"] = options;
      }
    }

    Json::StyledWriter writer;
    std::string result = writer.write(clone);

    return result;
  }
void ParticleHandler::initGrid(){
    
    
    side = pow((double)numParticles,0.334);
    ofVec3f steps(getWidthSpace()/side);
    positionInit.resize(numParticles,MyMatrixType::ColsAtCompileTime);
    for(int i = 0  ; i < numParticles ; i++){
        MatReal ii = (i%side) - side/2.0  +0.5;
        MatReal jj = (i/side)%(side) - side/2.0 + 0.5 ;
        MatReal kk = (int)(i/(side*side)) - side/2.0 +0.5;
        positionInit.row(i)[0] = ii*steps.x;
        positionInit.row(i)[1] = jj*steps.y;
#if COLNUM > 2
        positionInit.row(i)[2] = kk*steps.z;
#endif
    }
    
    //    int side = pow(numParticles,0.5);
    //    ofVec2f steps(widthSpace/side);
    //    for(int i = 0  ; i < numParticles ; i++){
    //        MatReal ii = (i%side) - side/2 ;
    //        MatReal jj = (int)(i/side) - side/2 ;
    //
    //        position.row(i)[0] = ii*steps.x;
    //        position.row(i)[1] = jj*steps.y;
    //        position.row(i)[2] = 0;
    //    }
    resetToInit();
    
}
Exemple #9
0
uint64_t freq_pstate_getCpuClockMax(const int cpu_id )
{
    char buff[256];
    unsigned int pct = 0;
    unsigned int maxFreq = getMax();
    if (num_steps == 0)
    {
        steps();
    }
    uint64_t clock = ((percent[num_steps-1]) * maxFreq) * 10;
    FILE* f = fopen("/sys/devices/system/cpu/intel_pstate/max_perf_pct","r");
    if (f != NULL)
    {
        char *eptr = fgets(buff, 256, f);
        if (eptr != NULL)
        {
            pct = strtoull(buff, NULL, 10);
            for (int i=num_steps-1; i >= 0; i--)
            {
                if (percent[i] == pct)
                {
                    //clock = freqs[i]*1000;
                    clock = ((percent[i]) * maxFreq) * 10; // *1000/100
                    break;
                }
            }
        }
        fclose(f);
    }
    return clock;
}
Exemple #10
0
    int arrayNesting(vector<int>& nums) {
        int n = nums.size();
        vector<int> steps(n, -1);
        int res = 0;
        for(int i = 0; i < n; ++i)
        {
            if(steps[i] == -1)
            {
                int t = i;
                vector<int> v;
                while(true)
                {
                    v.emplace_back(nums[t]);
                    if(nums[t] == i) break;
                    t = nums[t];
                }

                for(int j : v)
                {
                    steps[j] = v.size();
                }
                res = max(res, (int)v.size());
            }
        }
        return res;
    }
vector<int> GlobalSetting::steps() {
    vector<int> steps(4);
    steps[0] = 2;
    steps[1] = 5;
    steps[2] = 7;
    steps[3] = 9;
    return steps;
}
Exemple #12
0
 int climbStairs(int n) {
     vector<int> steps(3, 0);
     steps[0] = 1;
     steps[1] = 1;
     for (int i = 2; i <= n; ++i) {
         steps[i % 3] = steps[(i - 1) % 3] + steps[(i - 2) % 3];
     }
     return steps[n % 3];
 }
Exemple #13
0
void integrate(const int n, const double alpha, reconstruct r, complex_mesh_func cmf, data_t *d)
{
	double dt = cfl * 2.0 / n;
	mesh_t *m = (mesh_t*)malloc(sizeof(mesh_t));
	cmf(n, -1.0, 1.0, alpha, m);
	create_mesh_data(m, d);
	initial_sin4(0.0, d);
	steps(T / dt, 1.0, dt, d, r);
}
int
main (void)
{
  int i, j, r, c, sx, sy, gx, gy, min;
  int steps[50 * 50];
  char mass[2501], dummy;

  scanf ("%d %d", &r, &c);
  scanf ("%d %d", &sx, &sy);
  scanf ("%d %d", &gx, &gy);

  for (i = 0; i < r; i++)
    {
      scanf ("%c", &dummy);
      for (j = 0; j < c; j++)
	{
	  scanf ("%c", &mass (i, j));
	}
    }

  for (i = 0; i < 50 * 50; i++)
    {
      steps[i] = 2560;
    }

  steps (sx - 1, sy - 1) = 0;
  for (i = 0; i < r; i++)
    {
      for (j = 0; j < c; j++)
	{
	  if (strncmp (&mass (i, j), "#", 1) == 0)
	    {
	      steps (i, j) = WALL;
	    }
	}
    }

  search_around (sx - 1, sy - 1, 0, steps);
  min = steps (gx - 1, gy - 1);

  printf ("%d\n", min);

  return 0;
}
Exemple #15
0
  virtual void traffic_run()
  {

    // activities that may occur in the traffic flow

    // std::cout << *this;

    pursuit();

    steps();

  }
itk::Object::Pointer QmitkExhaustiveOptimizerView::GetOptimizer()
{
  itk::ExhaustiveOptimizer::Pointer OptimizerPointer = itk::ExhaustiveOptimizer::New();
  OptimizerPointer->SetStepLength(m_Controls.m_StepLengthExhaustive->text().toFloat());
  itk::ExhaustiveOptimizer::StepsType steps(m_NumberTransformParameters);
  for (int i = 0; i < m_NumberTransformParameters; i++)
  {
    steps[i] = m_Controls.m_NumberOfStepsExhaustive->text().toInt();
  }
  OptimizerPointer->SetNumberOfSteps(steps);
  return OptimizerPointer.GetPointer();
}
	int jump(int arr[], int n) {
		
		std::vector<int> steps(n, INT_MAX);
		
		steps[0] = 0;
		for (int i = 0; i < n; ++i) {
			if (i && (arr[i] < arr[i-1])) continue;
			for (int j = i + 1; j < std::min(n, i + 1 + arr[i]); ++j) steps[j] = std::min(steps[j], steps[i] + 1);
			if (steps.back() < INT_MAX) return (steps.back());
		}
		
		return (steps.back());
	}
Exemple #18
0
int steps(signed long* map, signed long n)
{
	//printf("Called with: %ld\n", n);
	if (n >= MAX_MEMORY)
	{
		return -1;
	}
	if (n < 0)
		return (signed long) 0;
	else if (n == 0)
		return (signed long) 1;
	else if (map[n] > 0)
		return map[n];
	else
	{
		//printf("%ld call, calling %ld, %ld, %ld\n", n, n-1, n-2, n-3);
		map[n] = steps(map, n-1) +
			steps(map, n-2) +
			steps(map, n-3);
		return map[n];
	}
}
Exemple #19
0
 int climbStairs(int n) {
     if (n == 1) {
         return 1;
     }
     
     vector<int> steps(n);
     steps[0] = 1;
     steps[1] = 2;
     
     for (int i = 2; i < n; i++) {
         steps[i] = steps[i - 1] + steps[i - 2];
     }
     return steps[n-1];
 }
Exemple #20
0
UInteger steps(UInteger seed) {
  UInteger s = 0;
  if( seed < CACHE_SIZE ) {
    s = g_stepsCache[seed];
    if( s > 0 )
      return s;
  }
  
  UInteger newSeed = (seed%2==0) ? (seed>>1) : (3*seed+1);
  
  s = steps(newSeed) + 1;
  if( seed < CACHE_SIZE )
    g_stepsCache[seed] = s;
  return s;
}
Exemple #21
0
  void 
  PotentialStepped::outputXML(magnet::xml::XmlStream& XML) const {
    XML << magnet::xml::attr("Type") << "Stepped";

    if (_direction)
      XML << magnet::xml::attr("Direction") << "Right";
    else
      XML << magnet::xml::attr("Direction") << "Left";

    for (size_t id(0); id < steps(); ++id)
      XML << magnet::xml::tag("Step")
	  << magnet::xml::attr("R") << _r_cache[id]
	  << magnet::xml::attr("E") << _u_cache[id]
	  << magnet::xml::endtag("Step");
  }
Exemple #22
0
 int jump(vector<int>& nums) {
     int n = nums.size();
     vector<int> steps(n);
     int i = 0;
     steps[0] = 0;
     for(int j = 0; i <= j && i < n; i ++) {
         if(i + nums[i] > j) {
             for(int k = j + 1; k <= i + nums[i] && k < n; k ++) {
                 steps[k] = steps[i] + 1;
             }
             j = i + nums[i];
         }
     }
     
     return steps[n - 1];
 }
Exemple #23
0
int ai_turn_black()
{
    int win=0;
    int x_axis,y_axis;
    x_axis=ana_x();
    y_axis=ana_y();
    
    
    steps(x_axis, y_axis, 'b');
    piece_GL('b', y_axis, x_axis);
    
    win=win_check_general(x_axis, y_axis, 'b');
    //printf("win=%d\n",win);
	return win;
    
}
/**
 * \brief Main function of the Focusing process
 */
void	MeasureFocusWork::main(astro::thread::Thread<FocusWork>& /* thread */) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "start focusing work");
	if (!complete()) {
		focusingstatus(Focusing::FAILED);
		throw std::runtime_error("focuser not completely specified");
	}
	counter = 0;

	// move to the minimum
	debug(LOG_DEBUG, DEBUG_LOG, 0, "measure left end of interval: %hu",
		min());
	FocusValue	left = measureat(min());
	FocusValue	right = measureat(max());
	
	// perform measurements at both ends of the interval
	FocusInterval	interval(left, right);

	// perform subdivisions
	double	resolution = (max() - min()) / pow(2, steps());
	debug(LOG_DEBUG, DEBUG_LOG, 0, "target resolution: %f", resolution);
	std::list<FocusInterval>	intervals;
	intervals.push_back(interval);
	try {
		while (interval.length() > resolution) {
			try {
				interval = subdivide(interval);
				intervals.push_back(interval);
			} catch (wronginterval) {
				debug(LOG_DEBUG, DEBUG_LOG, 0,
					"retrying other interval");
				intervals.pop_back();
				interval = *intervals.rbegin() - interval;
				intervals.push_back(interval);
			}
			debug(LOG_DEBUG, DEBUG_LOG, 0, "new interval: %s",
				interval.toString().c_str());
		}
		focusingstatus(Focusing::FOCUSED);
	} catch (std::exception& x) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "focus failed: %s", x.what());
		focusingstatus(Focusing::FAILED);
	} catch (...) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "unknown exception during focus");
		focusingstatus(Focusing::FAILED);
	}
}
Exemple #25
0
void Map::reset()
{
	/* initialize the map to all rock */
	for(unsigned int i(0); i < width_*height_; ++i)
	{
		tiles_[i] = getCurrentGame().tileAtlas_.at("rock");
	}


	/* set the seeds to generate the map */
	for(unsigned int i(0); i < grassSeeds_+waterSeeds_+forestSeeds_; ++i)
	{
		Seed seed1;
		seed1.pos_ = sf::Vector2i(uniform(0, int(width_-1)), uniform(0, int(height_-1)));
		if(i < grassSeeds_)
			seed1.tileType_ = "grass";
		else if(i < grassSeeds_ + waterSeeds_)
			seed1.tileType_ = "water";
		else
			seed1.tileType_ = "forest";
		seeds_[i] = seed1;
	}

	for(unsigned int i(0); i < width_*height_; ++i)
	{
		humidity_[i] = 0;
	}

	/* step and smooth */
	steps(steps_);
	smooths(smooths_);

	/*Set tiles positions and z-values in 2d world */
	for(int y = 0; y < height_; ++y)
	{
		for(int x = 0; x < width_; ++x)
		{
			sf::Vector2f pos;
			pos.x = (x - y) * tileSize_ + width_ * tileSize_;
			pos.y = (x + y) * tileSize_ * 0.5;
			tiles_[y*width_+x].sprite_.setPosition(pos);
			tiles_[y*width_+x].setZ(pos.y + tileSize_);
		}
	}
}
 int climbStairs(int n) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     if(n==0)
     return 0;
     if(n==1)
     return 1;
     if(n==2)
     return 2;
     
     vector<int> steps(n);
     steps[0]=1;
     steps[1]=2;
     for(int i=2;i<n;i++)
     steps[i]=steps[i-1]+steps[i-2];
     
     return steps[n-1];
 }
/**
 * \brief Subdivide a focus interval
 */
FocusInterval	MeasureFocusWork::subdivide(const FocusInterval& interval) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "interval subdivision %d", counter);
	if (counter > steps()) {
		throw std::runtime_error("number of steps exceeded");
	}
	FocusValue	v = measureat(interval.center());
	counter++;
	if ((v.value < interval.left().value) && (v.value < interval.right().value))  {
		throw wronginterval("new value is smaller than boundaries");
	}
	if (interval.left().value > interval.right().value) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "using left subdiv interval");
		return FocusInterval(interval.left(), v);
	} else {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "using right subdiv interval");
		return FocusInterval(v, interval.right());
	}
}
int Solution::climbStairs(int n)
{
	vector<int> steps(n , 0);
	for(int i=0; i<n; ++i)
	{
		if(!i)
			steps[i] = 1;
		else if(i==1)
			steps[i] = 2;
		else
		{
			int n1 = steps[i-1]; // 
			int n2 = steps[i-2];
			steps[i] = n1 + n2;
		}
	}
	
	return steps[n-1];
}
Exemple #29
0
void main(int argc, char* argv[])
{
	if (argc == 1)
		printf("use: ./child_steps <int>\n");
	else
	{
		signed long n = strtol(argv[1], NULL, 0);
		// printf("nth step: %ld\n", n);
		signed long* map = calloc(MAX_MEMORY, sizeof(signed long));
		signed long how_many = steps(map, n);
		if (how_many == -1)
		{
			printf("Exceeded memory boundary, quitting\n");
			printf("Increase MAX_MEMORY (line 3) and recompile\n");
		}
		else
			printf("Number of ways: %lu\n", how_many);
		free(map);
	}
}
Exemple #30
0
/* the following are for ai use*/
int ai_turn_white()
{
    int win=0;
    int x_axis,y_axis;

    //loop


    x_axis=ana_x();
    y_axis=ana_y();


    steps(x_axis, y_axis, 'w');
    piece_GL('w', y_axis, x_axis);

    win=win_check_general(x_axis, y_axis, 'w');
    //printf("win=%d\n",win);
    return win;

}