Пример #1
0
/**
  \brief Resi rovnici A*x=b
  \return x - vektor neznamych
  \param[in,out] LDU - matice do ktere bude zapsan ldu soucin
  \param[in] b - prava strana
*/
void MTX::solve_Axb(MTX& LDU, VTR& x, VTR& b){
    printf("\nMatice pred permutaci\n");
//    print_full_mtx();

    printf("\nPermutuji matici\n");
//    make_symbolic_factorization();
    //===========================
    make_permutation_ND();

    printf("\nAplikuji permutaci\n");

    apply_permutation();
    printf("\nPermutace aplikovana na matici\n");
    b.apply_permutation(MTX::P);
    printf("\nPermutace aplikovana na vektor b\n");
    //===========================
    LDU = *this;
    printf("\nMatice po permutaci\n");
//    print_full_mtx();
    printf("\nRozkladani matice\n");

//    try{
        make_ldu(LDU);
//    }catch(...){
//        std::cerr<<"Chyba: LDU Rozklad \n";
//        throw;
//    }
    printf("\n\nMatice rozlozena na LDU\n");
//    LDU.print_full_mtx();
    printf("\nVstupni vektor b:\n");
//    b.print();
    VTR z,y;
    LDU.solve_Lzb(b,z);
    printf("\nVysledny vektor z:\n");
//    z.print();
    LDU.solve_Dyz(z,y);
    printf("\nVysledny vektor y:\n");
//    y.print();
    LDU.solve_Uxy(y,x);
    printf("\nVysledny vektor x:\n");
    reverse_permutation_vector();
    apply_permutation();
    b.apply_permutation(MTX::P);
    x.apply_permutation(MTX::P);
//    x.print();
}
Пример #2
0
task_t planes_task_with_bounds(const size_t num_planes, const moment_t timespan, const moment_t bound_timespan)
{
    mt19937 randgen(static_cast<unsigned int>(std::time(0)));
    uniform_real_distribution<float> classes_distr(0, 1);
    uniform_real_distribution<float> priorities_distr(0, 1);
    uniform_real_distribution<moment_t> bounds_distr(bound_timespan * moment_t(0.7), bound_timespan);
    uniform_real_distribution<moment_t> dates_distr(bound_timespan, timespan);
    uniform_int_distribution<size_t> names_distr(0, sizeof(names) / sizeof(string));

    task_t task(num_planes);

    for (size_t i = 0; i < num_planes; ++i)
    {
        float p = classes_distr(randgen);
        if (p < 0.2)
            task[i].class_ = aircraft_t::LIGHT;
        else if (p > 0.8)
            task[i].class_ = aircraft_t::HEAVY;
        else
            task[i].class_ = aircraft_t::MEDIUM;
    }

    for (size_t i = 0; i < num_planes; ++i)
    {
        float p = priorities_distr(randgen);
        if (p < 0.2)
            task[i].priority_ = aircraft_t::RED;
        else if (p > 0.8)
            task[i].priority_ = aircraft_t::GREEN;
        else
            task[i].priority_ = aircraft_t::YELLOW;
    }

    for (size_t i = 0; i < num_planes; ++i)
    {
        task[i].name = ::names[i];
        task[i].due = dates_distr(randgen);
        task[i].min_bound = std::max(task[i].due - bounds_distr(randgen), moment_t(0));
        //task[i].min_bound = task[i].due;
        task[i].max_bound = task[i].due + bounds_distr(randgen);
    }

    perm_t due_perm = due_dates_perm(task);
    task = apply_permutation(task, due_perm);
    return task;
}
Пример #3
0
int
main(int argc, char** argv)
{
  int result;
  struct stat sb;
  char* file_name;
  char name[100] = "permutation";
  int len = strlen(name);
  uint32* histogram =NULL;
  uint32 gs, hgs;

  // Handle arguments
  convert_card_permutation(args.u, args.i); // LAMb: calculate hi/low from args!
  file_name = handle_arguments(argc, argv, &args);

  int size = args.s;
  uint32* permutation;
  uint32* graph = alloc_graph(size);
  gs = GRAPH_SIZE(size);
  hgs = gs + 1;

  if (args.i || args.a) {
    histogram = (uint32*) calloc(hgs, sizeof(uint32));
  }

  if (args.p)
  {
    permutation = alloc_permutation(size, false);
    str_to_permutation(args.p, permutation, false);
    if (args._2)
    {
      uint32* p2 = alloc_permutation(size, false);
      str_to_permutation(args._2, p2, false);
      apply_permutation(p2, permutation);
      free(p2);
    }

    map_perm_to_graph(permutation, graph);
    if (args.d) {
      graph_to_dot(graph, permutation, name, args.c, args.e);
    }
    if (histogram) {
      count_edges(graph, histogram, size);
    }
  }
  else if (args.l <= 0)
  {
    if (size > 7) {
      error("Can not generate more then 7! files.");
    }
    permutation = alloc_permutation(size, true);
    uint32 numPerms = factorial(size);
    for (int i=0; i < numPerms; i++)
    {
      map_perm_to_graph(permutation, graph);
      if (args.d) {
        graph_to_dot(graph, permutation, make_name(name, i), args.c, args.e);
      }
      if (histogram) {
        count_edges(graph, histogram, size);
      }
      name[len] = '\0';
      lex_permute(permutation+1, size);
    }
  }
  else
  {
    permutation = alloc_permutation(size, true);
    uint32 numPerms = factorial(size);
    for (int i=0; i < numPerms; i++)
    {
      if (i == args.l)
      {
        map_perm_to_graph(permutation, graph);
        if (args.d) {
          graph_to_dot(graph, permutation, make_name(name, i), args.c, args.e);
        }
        name[len] = '\0';
        break;
      }
      lex_permute(permutation+1, size);
    }
  }

  if (args.i)
  {
    for (int i=0; i < hgs; i++) {
      printf("%i\t", i);
    }
    printf("\n");
    for (int i=0; i < hgs; i++) {
      printf("%i\t", histogram[i]);
    }
    printf("\n");
  }

  if (args.a)
  {
    uint64 sum =0, count =0;
    for (int i=0; i < hgs; i++) {
      sum += histogram[i] * i;
      count += histogram[i];
    }
    double d = sum / (double) count;
    printf("average: %llu, %llu, %f\n", sum, count, d);
  }

  if (histogram) free(histogram);
  free(permutation);
  free(graph);
  exit(result);
}