コード例 #1
0
MlSlotStats MlSlotList::calculate_stats() {
  MlSlotStats::l1_size_t l1_occ;
  MlSlotStats::l2_size_t l2_occ;
  size_t tot_l1 = 0, tot_l2 = 0;

  for(uint32_t i=0; i<l1_len; ++i) {
    l1_occ[i] = algo(count_if, l1_slots[i], not_empty);
    tot_l1 += l1_occ[i];
  }
  for(uint32_t i=0; i<l2_len; ++i) {
    l2_occ[i] = algo(count_if, l2_slots[i], not_empty);
    tot_l2 += l2_occ[i];
  }

  double wasted_perc = 100. * (tot_fix_len - tot_l1 - tot_l2) / tot_fix_len;
  MY_ASSERT(wasted_perc >= 0.0);

  MlSlotStats stats = {
    l1_occ,
    l2_occ,
    last_resort.size(),
    calculate_compaction(),
    wasted_perc,
  };
  return stats;
}
コード例 #2
0
ファイル: algo.c プロジェクト: vatout/sudoky-resolver
int		algo(char **tab, int pos)
{
  int		x;
  int		y;
  char		k;

  x = pos % 9;
  y = pos / 9;
  k = '1';

  if (pos == 81)
    return (0);
  if (tab[y][x] != ' ')
    return (algo(tab, (pos + 1)));
  while (k <= '9')
    {
      if ((algo_line(tab, y, k) == 0) && (algo_cols(tab, x, k) == 0)
	  && (algo_square(tab, x, y, k) == 0))
        {
	  tab[y][x] = k;
	  if (algo(tab, (pos + 1)) == 0)
	    return (0);
        }
      k = k + 1;
    }
  tab[y][x] = ' ';
  return (1);
}
コード例 #3
0
ファイル: uppg1.cpp プロジェクト: kwabe007/spel-spelet
int main() {
    int test1[5] = {1,2,1,2,1};
    int * test1end = test1 + 5;
    bool answer1 = algo(test1, test1end);

    int test2[6] = {1,2,1,2,1,2};
    int * test2end = test2 + 6;
    bool answer2 = algo(test2, test2end);

    int test3[6] = {1,2,1,2,1,3};
    int * test3end = test3 + 6;
    bool answer3 = algo(test3, test3end);

    int test4[5] = {2,1,2,1,2};
    int * test4end = test4 + 5;
    bool answer4 = algo(test4, test4end);

    int test5[1] = {1};
    int * test5end = test5 + 1;
    bool answer5 = algo(test5, test5end);


    std::cout << "Answer1: " << answer1 << std::endl;
    std::cout << "Answer2: " << answer2 << std::endl;
    std::cout << "Answer3: " << answer3 << std::endl;
    std::cout << "Answer4: " << answer4 << std::endl;
    std::cout << "Answer5: " << answer5 << std::endl;



    return 0;
}
コード例 #4
0
ファイル: t-moeoNSGAII.cpp プロジェクト: AdeleH/paradiseo
int main()
{
    std::cout << "[moeoNSGAII]" << std::endl;

    TestEval eval;
    eoPopLoopEval <Solution> popEval(eval);
    eoQuadCloneOp < Solution > xover;
    eoUniformMutation < Solution > mutation(0.05);

    eoRealVectorBounds bounds(1, 1.0, 2.0);
    eoRealInitBounded < Solution > init(bounds);
    eoPop < Solution > pop(20, init);
    eoQuadGenOp <Solution> genOp(xover);
    eoSGATransform < Solution > transform(xover, 0.1, mutation, 0.1);
    eoGenContinue <Solution > continuator(10);

    // build NSGA-II
    moeoNSGAII < Solution > algo(20, eval, xover, 1.0, mutation, 1.0);
    moeoNSGAII < Solution > algo2(continuator, eval, genOp);
    moeoNSGAII < Solution > algo3(continuator, popEval, genOp);
    moeoNSGAII < Solution > algo4(continuator, eval, transform);
    moeoNSGAII < Solution > algo5(continuator, popEval, transform);

    // run the algo
    algo(pop);

    // final pop
    std::cout << "Final population" << std::endl;
    std::cout << pop << std::endl;

    std::cout << "[moeoNSGAII] OK" << std::endl;
    return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: openssl.c プロジェクト: stinb/libssh2
int
_libssh2_cipher_init(_libssh2_cipher_ctx * h,
                     _libssh2_cipher_type(algo),
                     unsigned char *iv, unsigned char *secret, int encrypt)
{
#ifdef HAVE_OPAQUE_STRUCTS
    *h = EVP_CIPHER_CTX_new();
    return !EVP_CipherInit(*h, algo(), secret, iv, encrypt);
#else
    EVP_CIPHER_CTX_init(h);
    return !EVP_CipherInit(h, algo(), secret, iv, encrypt);
#endif
}
コード例 #6
0
ファイル: Workshop6_1.c プロジェクト: czarcrab/Zorro
function run()
{
	set(PARAMETERS);  // generate and use optimized parameters
	NumCores = -2;		// use multiple cores (Zorro S only)
	BarPeriod = 60;		// 1 hour bars
	LookBack = 2000;	// needed for Fisher()
	StartDate = 2005;
	EndDate = 2015; 	// fixed simulation period
	NumWFOCycles = 10; // activate WFO
	
	if(ReTrain) {
		UpdateDays = -1;	// update price data from the server 
		SelectWFO = -1;	// select the last cycle for re-optimization
	}
	
// portfolio loop
	while(asset(loop("EUR/USD","USD/JPY")))
	while(algo(loop("TRND","CNTR")))
	{
		if(Algo == "TRND") 
			tradeTrend();
		else if(Algo == "CNTR") 
			tradeCounterTrend();
	}
	
	PlotWidth = 600;
	PlotHeight1 = 300;
	set(TESTNOW);
}
コード例 #7
0
ファイル: k-partitioning.c プロジェクト: ICLDisco/ompi
int* kPartitioning(double ** comm, int n, int k, int * constraints, int nb_constraints, int greedy_trials)
{
  /* ##### declarations & allocations ##### */

  PriorityQueue Qpart, *Q = NULL, *Qinst = NULL;
  double **D = NULL;
  int deficit, surplus, *part = NULL;
  int real_n = n-nb_constraints;

  part = build_p_vector(comm, n, k, greedy_trials, constraints, nb_constraints);

  memory_allocation(&Q, &Qinst, &D, real_n, k);

  /* ##### Initialization ##### */

  initialization(part, comm, &Qpart, Q, Qinst, D, real_n, k, &deficit, &surplus);

  /* ##### Main loop ##### */
  while((nextGain(&Qpart, Q, &deficit, &surplus))>0)
    {
      algo(part, comm, &Qpart, Q, Qinst, D, real_n, &deficit, &surplus);
    }

  /* ##### Balancing the partition  ##### */
  balancing(real_n, deficit, surplus, D, part); /*if partition isn't balanced we have to make one last move*/

  /* ##### Memory deallocation ##### */
  destruction(&Qpart, Q, Qinst, D, real_n, k);

  return part;
}
コード例 #8
0
ファイル: solver3.hpp プロジェクト: Barbakas/LMA
    Solver& solve(const AlgoTag& config = LdltTag<>(), const F &callbacks = default_callbacks_for_solver())
    {
      if (bundle.nb_obs()==0)
      {
        return *this;
      }

      rms1 = 0;
      rms2 = 0;
      it_interne = 0;
      is_better = true;

      typedef typename SelectAlgo<Container,Container::NbClass,AlgoTag>::type Algorithm;
      Algorithm algo(config);
      
      algo.init(bundle);

      algo.compute_erreur(bundle);
      rms1 = rms2 = initial_cost = algo.get_erreur();

      callbacks.at_begin_bundle_adjustment(*this,algo);
      
      for( ; it_interne < nb_iteration_interne ; ++it_interne)
      {
        if (!update(algo,callbacks)) break;
      }

      final_cost = algo.get_erreur();

      callbacks.at_end_bundle_adjustment(*this,algo);
      return *this;
    }
コード例 #9
0
ファイル: main.c プロジェクト: kc1212/gcjam
int main(void)
{
	int cutoff = 0, T = 0, N = 1000, Tries = 1000;
	int a[N];
	srand(time(NULL));
	scanf("%d", &T);
	assert(T == 120);

	int tot_score = 0;
	for (int i = 0; i < Tries; i++) {
		algo(a, N, 0); // bad algorithm
		tot_score += score(a,N);
	}
	cutoff = (double)tot_score / Tries;
	assert(cutoff == 528);

	for (int i = 0; i < T; i++) {
		int tmp;
		scanf("%d", &tmp);
		assert(tmp == N);

		for (int j = 0; j < N; j++)
			scanf("%d", a+i);

		printf("Case #%d: ", i+1);
		// algo(a, N, 1);
		// printf("%f - %f\n", (double)score(a,N), (cutoff + 500) / 2.0);
		if (score(a,N) > (cutoff + 500) / 2.0 )
			printf("BAD\n");
		else
			printf("GOOD\n");
	}

	return 0;
}
コード例 #10
0
ファイル: GatherInterface.cpp プロジェクト: SRI-CSL/OCCAM
  bool
  GatherInterface(Function& F, ComponentInterface& C, AliasAnalysis* aa)
  {
    if (F.isDeclaration()) {
      errs() << "Gather interface of undefined function '" << F.getName() << "'\n";
      return true;
    }

    std::set<Function*> visited;
    std::queue<Function*> worklist;

    GatherReferences algo(&C, aa, &worklist);

    worklist.push(&F);
    while (!worklist.empty()) {
      Function* f = worklist.front();
      worklist.pop();

      if (visited.find(f) != visited.end())
        continue;

      algo.visit(f);

      if (algo.anyUnknown) {
        // TODO: This is a safety precaution, we should be able to
        //       take advantage of a global alias analysis to get
        //       a better set
        GatherInterface(*F.getParent(), C, aa);
        return false;
      }
      visited.insert(f);
    }
    return true;
  }
コード例 #11
0
ファイル: bsq.c プロジェクト: dubus-b/BSQ
int		main(int argc, char **argv)
{
  t_info_array	board;
  t_pos_square	result;
  char		*file;
  char		*line_file;
  char		*map;

  board.nb_line = 0;
  board.nb_col = 0;
  board.array = NULL;
  if (argc == 1)
    my_putstr("Usage: ./bsq [FILE] ");
  file = fd(argv);
  line_file = line(file);
  board.nb_line = my_getnbr(line_file);
  free(line_file);
  map = maps(file);
  board.nb_col = my_col_nbr(map);
  board.array = get_array(map, board.nb_line, board.nb_col, 0);
  algo(&board, &result, 0, 0);
  modif_map(&board, &result);
  my_putchar_et(&board);
  free(file);
  return (0);
}
コード例 #12
0
ファイル: HW6.c プロジェクト: tjisana/IEOR4739
int main(int argc,char** argv){
    int N=50;
    int T=25;
    char* act = (char*)calloc(1000000,sizeof(char));    
    algo(N,T,"squareinverse","squareroot",act);
    return 0;    
}
コード例 #13
0
void lunar_dx9_block :: move (void) {
	if (current_algo != previous_algo) {
		switch ((int) current_algo) {
		case 0: algo = algo1; break;
		case 1: algo = algo2; break;
		case 2: algo = algo3; break;
		case 3: algo = algo4; break;
		case 4: algo = algo5; break;
		case 5: algo = algo6; break;
		case 6: algo = algo7; break;
		case 7: algo = algo8; break;
		default: algo = algo1; break;
		}
		previous_algo = current_algo;
	}
	if (trigger >= 16384.0) time1 = time2 = time3 = time4 = 0.0;
	signal = algo (this);
	time1 += core -> TimeDelta (freq1) * ratio1;
	time2 += core -> TimeDelta (freq2) * ratio2;
	time3 += core -> TimeDelta (freq3) * ratio3;
	time4 += core -> TimeDelta (freq4) * ratio4;
	while (time1 >= 1.0) time1 -= 1.0;
	while (time2 >= 1.0) time2 -= 1.0;
	while (time3 >= 1.0) time3 -= 1.0;
	while (time4 >= 1.0) time4 -= 1.0;
}
コード例 #14
0
ファイル: AppMeshPartPy.cpp プロジェクト: neuroidss/FreeCAD
    Py::Object wireFromSegment(const Py::Tuple& args)
    {
        PyObject *o, *m;
        if (!PyArg_ParseTuple(args.ptr(), "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
            throw Py::Exception();

        Py::List list(o);
        Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
        std::vector<unsigned long> segm;
        segm.reserve(list.size());
        for (unsigned int i=0; i<list.size(); i++) {
            segm.push_back((int)Py::Int(list[i]));
        }

        std::list<std::vector<Base::Vector3f> > bounds;
        MeshCore::MeshAlgorithm algo(mesh->getKernel());
        algo.GetFacetBorders(segm, bounds);

        Py::List wires;
        std::list<std::vector<Base::Vector3f> >::iterator bt;

        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
            BRepBuilderAPI_MakePolygon mkPoly;
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
            }
            if (mkPoly.IsDone()) {
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
                wires.append(Py::Object(wire, true));
            }
        }

        return wires;
    }
コード例 #15
0
ファイル: openssl.c プロジェクト: tomgr/libssh2
int
_libssh2_cipher_init(_libssh2_cipher_ctx * h,
                     _libssh2_cipher_type(algo),
                     unsigned char *iv, unsigned char *secret, int encrypt)
{
    EVP_CIPHER_CTX_init(h);
    return !EVP_CipherInit(h, algo(), secret, iv, encrypt);
}
コード例 #16
0
void algo(int left, int right, int index)
{
	if (index < 0 || index >= n)
	{
		return;
	}
	if (check[index])
	{
		return;
	}

	check[index] = 1;
	printf("%d ", postorder[index]);
	int temp_right = inf[postorder[index]];
	algo(left, temp_right - 1, index - (right + 1 - inf[postorder[index]]));
	algo(temp_right + 1, right, index - 1);
}
コード例 #17
0
ファイル: ask_game.c プロジェクト: heitzls/Allum1
void     ask_game_cpu(t_data *data, t_window *w)
{
  SDL_BlitSurface(w->background_g, NULL, w->ecran, &w->pos_background_c);
  aff_game_cpu_SDL(data, w);
  SDL_BlitSurface(w->cpu, NULL, w->ecran, &w->pos_cpu);
  SDL_Flip(w->ecran);
  data->last_player = 2;
  algo(data, w);
}
コード例 #18
0
void TreeIt::fill_buffer() {
  int row_idx = 0;
  std::transform(l1_cur.begin(), l1_cur.end(), std::back_inserter(buffer),
    [this, &row_idx](size_t& idx) { 
      const auto& row = parent.l1_slots[row_idx++];
      uint32_t val = slot_empty;
      if(idx < l1_size && row[idx] != slot_empty)
        val = (uint32_t)(idx * l1_mult + row[idx]);
      //LOG("row_idx=" << row_idx << " idx=" << idx << " val1=" << val);
      idx += idx < l1_size ? 1 : 0;
      return val;
  });

  row_idx = 0;
  auto ceil = l1_cur[0] * l1_mult + slot_min_val;

  std::transform(l2_cur.begin(), l2_cur.end(), std::back_inserter(buffer),
    [this, &row_idx, ceil](size_t& idx) { 
      const auto& row = parent.l2_slots[row_idx++];
      uint32_t val = slot_empty;
      if(idx < l2_size && row[idx] != slot_empty) {
        val = (uint32_t)(idx * l2_mult + row[idx]);
        //LOG("row_idx=" << row_idx << " idx=" << idx << " val=" << val);
      }
      if(val >= ceil)
        val = slot_empty;
      else {
        //LOG("row_idx=" << row_idx << " idx=" << idx << " val2=" << val);
        idx += idx < l2_size ? 1 : 0;
      }
      return val;
  });

  const auto& last = parent.last_resort;
  for(; last_cur < last.size() && last[last_cur] < ceil; ++last_cur)
    buffer.push_back(last[last_cur]);

  buffer.erase(algo(remove, buffer, slot_empty), buffer.end());
  algo(sort, buffer, std::greater<uint32_t>());
  std::transform(buffer.begin(), buffer.end(), buffer.begin(),
    [](uint32_t val) { return val - slot_min_val; }
  );
}
コード例 #19
0
void
MiniTensor_Minimizer<T, N>::
solve(
    std::string const & algoname,
    Teuchos::ParameterList & params,
    FN & fn,
    Intrepid2::Vector<T, N> & soln)
{
  step_method_name = algoname.c_str();
  function_name = FN::NAME;
  initial_guess = soln;

  Intrepid2::Vector<T, N>
  resi = fn.gradient(soln);

  initial_value = fn.value(soln);
  previous_value = initial_value;
  failed = failed || fn.failed;
  initial_norm = Intrepid2::norm(resi);

  // Define algorithm.
  ROL::MiniTensor_Objective<FN, T, N>
  obj(fn);

  ROL::Algorithm<T>
  algo(algoname, params);

  // Set Initial Guess
  ROL::MiniTensorVector<T, N>
  x(soln);

  // Run Algorithm
  algo.run(x, obj, verbose);

  soln = ROL::MTfromROL<T, N>(x);

  resi = fn.gradient(soln);

  T const
  norm_resi = Intrepid2::norm(resi);

  updateConvergenceCriterion(norm_resi);

  ROL::AlgorithmState<T> &
  state = const_cast<ROL::AlgorithmState<T> &>(*(algo.getState()));

  ROL::StatusTest<T>
  status(params);

  converged = status.check(state) == false;
  recordFinals(fn, soln);

  return;
}
コード例 #20
0
bool MlSlotList::add_number_l2(uint32_t number) {
  uint16_t rem = number % l2_mult;
  uint32_t qot = number / l2_mult;

  auto it = algo(find_if, l2_slots, [&](std::vector<uint16_t>& v) {
    auto empty = is_empty(v[qot]);
    if(empty) v[qot] = rem + slot_min_val;
    return empty;
  });
  return it != l2_slots.end();
}
コード例 #21
0
ファイル: C4MapScript.cpp プロジェクト: farad91/openclonk
static bool FnLayerBlit(C4PropList * _this, C4PropList *mask_algo, C4ValueArray *rect)
{
	// Layer script function: Blit mask_algo onto surface of _this  within bounds given by rect
	C4MapScriptLayer *layer = _this->GetMapScriptLayer();
	if (!layer) return false;
	C4Rect rcBounds;
	if (!FnParRect(layer, rect, &rcBounds)) return false;
	std::unique_ptr<C4MapScriptAlgo> algo(FnParAlgo(mask_algo));
	if (!algo.get()) return false;
	return layer->Blit(rcBounds, algo.get());
}
コード例 #22
0
ファイル: C4MapScript.cpp プロジェクト: farad91/openclonk
static bool FnLayerDraw(C4PropList * _this, C4String *mattex, C4PropList *mask_algo, C4ValueArray *rect)
{
	// Layer script function: Draw material mattex in shape of mask_algo in _this layer within bounds given by rect
	C4MapScriptLayer *layer = _this->GetMapScriptLayer();
	uint8_t fg, bg;
	if (!layer || !FnParTexCol(mattex, fg, bg)) return false;
	C4Rect rcBounds;
	if (!FnParRect(layer, rect, &rcBounds)) return false;
	std::unique_ptr<C4MapScriptAlgo> algo(FnParAlgo(mask_algo));
	return layer->Fill(fg, bg, rcBounds, algo.get());
}
コード例 #23
0
ファイル: 재귀_2진수변환.cpp プロジェクト: imgosari/acm
void algo(int n, int idx)
{
	if(n<=1)
	{
		printf("%d",n);
		return;
	}
	int t = arr[n/2];
	algo(n/2, idx+1);
	arr[idx] = n%2;
	printf("%d",arr[idx]);
}
コード例 #24
0
ファイル: main.cpp プロジェクト: CCJY/coliru
void algo(std::vector<std::vector<int> >& result, std::vector<int> path, std::vector<int> tasks)
{
	for(auto it = std::begin(tasks), itend = std::end(tasks) ; it != itend ; ++it) {
		std::vector<int> temp(std::begin(tasks), it);
		std::copy(it + 1, itend, std::back_inserter(temp));

		path.push_back(*it);
		result.push_back(path);
		algo(result, path, temp);
		path.pop_back();
	}
}
コード例 #25
0
ファイル: main.c プロジェクト: JACOBFelix/lem-in
int		main(void)
{
  t_infos	infos;

  if (parser(&infos) == FAILURE)
    return (1);
  if (check_init(&infos) == FAILURE)
    return (1);
  algo(&infos);
  free_anthill(infos.first);
  return (0);
}
コード例 #26
0
ファイル: g-nbr-ilots.c プロジェクト: Epicheat/Exam-C-tek-2
int	main(int ac, char **av)
{
  char	**nodes;

  if (ac != 2)
    return (printf("\n"));
  if (!(nodes = parse(av[1])))
    return (1);
  printf("%i\n", algo(nodes));
  free(nodes);
  return (0);
}
コード例 #27
0
ファイル: island.cpp プロジェクト: jmp75/paradiseo
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::operator()()
{
    stopped = false;
    algo(pop);
    stopped = true;
    // Let's wait the end of communications with the island model
    for(auto& message : sentMessages)
        message.wait();
    
    // Clear the sentMessages container
    sentMessages.clear();
}
コード例 #28
0
ファイル: parser.c プロジェクト: Saruta/a2c
struct algo *parse_procedure()
{
  eat(PROCEDURE);
  eat(IDENTIFIER);
  char *ident = strdup(tok->val);
  eat(EOL);
  struct declarations *decls = parse_decls();
  eat(BEGIN); eat(EOL);
  instructionlist_t block = parse_block();
  eat(END); eat(ALGORITHM); eat(PROCEDURE); eat(IDENTIFIER);
  if (lookahead[0]->type == EOL) eat(EOL);
  return algo(ident, NULL, decls, block);
}
コード例 #29
0
ファイル: g-diam.c プロジェクト: Epicheat/Exam-C-tek-2
int	main(int ac, char **av)
{
  char	**nodes;
  int	result;

  if (ac != 2
      || !(nodes = parse(av[1]))
      || (result = algo(nodes)) == -1)
    return (printf("\n"));
  printf("%i\n", result);
  free(nodes);
  return (0);
}
コード例 #30
0
ファイル: main.c プロジェクト: kevinjojo007/game-of-life
int			main(int ac, char **av)
{
	char	before[SIZE_X][SIZE_Y];
	char	after[SIZE_X][SIZE_Y];

	(void)ac;
	clear_map(before);
	clear_map(after);
	init_map(before, ft_atoi(av[1]));
	show_map(before);
	usleep(TURN_TIME);
	algo(before, after, ft_atoi(av[2]));
	return (0);
}