std::string InputOutputException::get_message(ModelObject *o) const {
  std::ostringstream oss;
  switch (get_entity()) {
    case DERIVATIVE:
      if (o->get_model()->get_stage() == BEFORE_EVALUATING) {
        oss << "Derivatives cannot be read before evaluating.";
        break;
      }
    default:
      switch (get_operation()) {
        case GET:
          oss << "Not in input list.";
          break;
        case SET:
        case ADD:
        case REMOVE:
          oss << "Not in output list.";
          break;
        default:
          // should not exist
          oss << "Unknown read/write error";
      }
      break;
  };
  oss << " Violating object: \"" << o->get_name() << "\".";
  if (particle_index_ >= 0) {
    oss << " Attribute " << get_key_name() << " of particle \""
        << o->get_model()
               ->get_particle(ParticleIndex(get_particle_index()))
               ->get_name() << "\" with id " << get_particle_index();
  } else {
    oss << "Container \"" << container_name_ << "\".";
  }
  return oss.str();
}
Example #2
0
File: menu.c Project: reinka/coding
int main(int argc, const char * argv[]) {
    
    struct address data[SIZE];
    int i = 0, operation;
    
    while (1) {
        
        get_operation(&operation);
        
        if (operation == 2) {
            break;
        }
        else if (operation == 0){
            if (i < SIZE){
                data[i++] = input_address();
            }
            else
                puts("\n\nDatensatz voll. Keine Aufnahme zusaetzlicher Daten moeglich.\n\n");
        }
        else if (operation == 1){
            if(i == 0){
                puts("\n\nEs sind noch keine Datensaetze vorhanden. Geben Sie bitte erst welche ein.\n\n");
            }
            else{
                for (int j = 0; j < i ; j++) {
                    print_address(&data[j]);
                }
            }   
        }
        
    }
    return EXIT_SUCCESS;
}
Example #3
0
    void Table::add_instruction (
        std::string& predicate, 
        std::string& operation,
        std::string& destination,
        std::string& operand1,
        std::string& operand2,
        std::string& shift_type,
        std::string& shamt
    ) 
    {
        Instruction op;

        get_predicate(predicate, op);
        get_operation(operation, op);
        get_destination(destination, op);
        get_operand1(operand1, op);
        get_operand2(operand2, op);
        get_shift_type(shift_type, op);
        get_shamt(shamt, op);

        op.stop_bit = false;
        op.size     = instruction_size[op.type];
        op.address  = address;
        address    += op.size;
       
        instructions.push(op); 
    }
Example #4
0
int main(int argc, char **argv)
{
	get_operation(argc, argv);
	Cache cache;
    initialize_cache(&cache);
    read_file(&cache);
    printSummary(num_hit,num_miss,num_eviction);
	return 0;
}
Example #5
0
Word Solver :: find_best_M (std::string operation_name, int M_index) {
    Operation * operation;
    Add * adder;
    Word result;
    
    operation = get_operation(operation_name);
    adder = dynamic_cast<Add *>(operation);
    
    result = adder->best_adder(M[M_index]->g_name());

    return result;
}
Example #6
0
/* Arg1 is program file, arg2 is codel size in pixels. */
int main(int argc, char *argv[])
{
	if (argc != 3) {
		printf("Usage: piet <image> <codel size>\n");
		return 1;
	}

	load_program(argv[1], atoi(argv[2]));

	if (!program.image) {
		fprintf(stderr, "Program not found/not valid\n");
		return 1;
	}

	interp.dp = 0;
	interp.cc = -1;
	interp.current.x = 0;
	interp.current.y = 0;
	get_codel_color(&interp.current);

	int found;

	do {
		struct codel next;

		if (interp.current.color == WHITE) {
			if (slide_white(&next))
				interp.current = next;
			else
				break;
		}

		found = get_next_block(&next);
		if (found) {
			if (next.color == WHITE) {
				interp.current = next;
			} else {
				const struct operation *op = get_operation(&next);
				op->op();
				interp.current = next;
			}
		}
	} while(found);

	free(program.image);

	return 0;
}
Example #7
0
/*
 * Load one action attribute.
 */
static int
get_action_attribute(
			FILE * inFile, 
			ABObj obj,
			ABObj module,
                     	ABObj action,
                     	AB_GIL_ATTRIBUTE attr
)
{
    int                 return_value = 0;
    int                 rc = 0; /* r turn code */

    if (abio_get_eof(inFile))
    {
        return (abil_print_load_err(ERR_EOF), -1);
    }

    switch (attr)
    {
    case AB_GIL_FROM:
        rc = get_from(inFile, obj, module, action);
        break;
    case AB_GIL_ACTION:
        rc = get_operation(inFile, action);
        break;
    case AB_GIL_TO:
        rc = get_to(inFile, obj, module, action);
        break;
    case AB_GIL_WHEN:
        rc = get_when(inFile, obj, action);
        break;
    case AB_GIL_FUNCTION_TYPE:
        rc = get_function_type(inFile, action);
        break;
    case AB_GIL_ARG_TYPE:
        rc = get_arg_type(inFile, action);
        break;
    default:
        abil_print_load_err(ERR_UNKNOWN);
    }

    return return_value;
}
void change_access_pattern(state_type *state, transaction_descriptor * transaction) {
	int l=0, di_id;
	// Get the client configuration from simulation state
	CLIENT_lp_state_type *pointer = &state->type.client_state;
	operation_descriptor * op= transaction->first_operation;
	do {
			op->object_key_id = -1;
			op=op->next;
	} while(op!=NULL);
	op= transaction->first_operation;
	do {
		do {
			di_id = RandomRange(0, state->cache_objects - 1);
			l = get_operation(transaction, di_id);
		} while (l);
		op->object_key_id=di_id;
		op=op->next;
} while(op!=NULL);
}
Example #9
0
/* Extract the operation patterns from args START through ARGC - 1 of ARGV. */
void
parse_operations (int argc, int start, char **argv)
{
  int i = start;	/* Index into ARGV. */
  size_t field;
  enum operation op;

  while ( i < argc )
    {
      op = get_operation (argv[i]);
      i++;
      if ( i >= argc )
        error (EXIT_FAILURE, 0, _("missing field number after " \
                                  "operation '%s'"), argv[i-1] );
      field = safe_get_field_number (op, argv[i]);
      i++;

      new_field_op (op, field);
    }
}
Example #10
0
Symmetry * sym_get_operation( SPGCONST Cell *cell,
			      const double symprec ) {
  int i, j, num_sym;
  MatINT *rot;
  VecDBL *trans;
  Symmetry *symmetry;
  
  rot = mat_alloc_MatINT( cell->size * 48 );
  trans = mat_alloc_VecDBL( cell->size * 48 );

  num_sym = get_operation( rot->mat, trans->vec, cell, symprec );

#ifdef DEBUG
  debug_print("*** get_symmetry (found symmetry operations) *** \n");
  debug_print("Lattice \n");
  debug_print_matrix_d3(cell->lattice);
  for ( i = 0; i < num_sym; i++ ) {
    debug_print("--- %d ---\n", i + 1);
    debug_print_matrix_i3(rot->mat[i]);
    debug_print("%f %f %f\n",
  		trans->vec[i][0], trans->vec[i][1], trans->vec[i][2]);
  }
#endif
  
  symmetry = sym_alloc_symmetry( num_sym );
  for ( i = 0; i < num_sym; i++ ) {
    mat_copy_matrix_i3(symmetry->rot[i], rot->mat[i]);
    for (j = 0; j < 3; j++)
      symmetry->trans[i][j] = trans->vec[i][j];
  }

  mat_free_MatINT( rot );
  mat_free_VecDBL( trans );

  return symmetry;
}
/* Add PATH to the operations tree rooted at OPERATION, creating any
   intermediate nodes that are required.  Here's what's expected for
   each action type:

      ACTION          URL    REV      SRC-FILE  PROPNAME
      ------------    -----  -------  --------  --------
      ACTION_MKDIR    NULL   invalid  NULL      NULL
      ACTION_CP       valid  valid    NULL      NULL
      ACTION_PUT      NULL   invalid  valid     NULL
      ACTION_RM       NULL   invalid  NULL      NULL
      ACTION_PROPSET  valid  invalid  NULL      valid

   Node type information is obtained for any copy source (to determine
   whether to create a file or directory) and for any deleted path (to
   ensure it exists since svn_delta_editor_t->delete_entry doesn't
   return an error on non-existent nodes). */
static svn_error_t *
build(struct editor_baton *eb,
      action_code_t action,
      const char *relpath,
      const char *url,
      svn_revnum_t rev,
      apr_hash_t *props,
      const char *src_file,
      svn_revnum_t head,
      apr_pool_t *scratch_pool)
{
  apr_array_header_t *path_bits = svn_path_decompose(relpath, scratch_pool);
  const char *path_so_far = "";
  struct operation *operation = &eb->root;
  int i;

  /* We should only see PROPS when action is ACTION_PROPSET. */
  SVN_ERR_ASSERT((props && action == ACTION_PROPSET)
                || (!props && action != ACTION_PROPSET) );

  /* Look for any previous operations we've recognized for PATH.  If
     any of PATH's ancestors have not yet been traversed, we'll be
     creating OP_OPEN operations for them as we walk down PATH's path
     components. */
  for (i = 0; i < path_bits->nelts; ++i)
    {
      const char *path_bit = APR_ARRAY_IDX(path_bits, i, const char *);
      path_so_far = svn_relpath_join(path_so_far, path_bit, scratch_pool);
      operation = get_operation(path_so_far, operation, eb->edit_pool);
    }

  /* Handle property changes. */
  if (props)
    {
      SVN_ERR(eb->fetch_kind_func(&operation->kind, eb->fetch_kind_baton,
                                  relpath, scratch_pool));

      /* If we're not adding this thing ourselves, check for existence.  */
      if (! ((operation->operation == OP_ADD) ||
             (operation->operation == OP_REPLACE)))
        {
          if ((operation->kind == svn_node_file)
                   && (operation->operation == OP_OPEN))
            operation->operation = OP_PROPSET;
        }
      operation->props = svn_prop_hash_dup(props, eb->edit_pool);
      if (!operation->rev)
        operation->rev = rev;
      return SVN_NO_ERROR;
    }

  if (action == ACTION_RM)
    operation->operation = OP_DELETE;

  /* Handle copy operations (which can be adds or replacements). */
  else if (action == ACTION_CP)
    {
      operation->operation =
        operation->operation == OP_DELETE ? OP_REPLACE : OP_ADD;

      SVN_ERR(eb->fetch_kind_func(&operation->kind, eb->fetch_kind_baton,
                                  relpath, scratch_pool));
      operation->url = url;
      operation->rev = rev;
    }
  /* Handle mkdir operations (which can be adds or replacements). */
  else if (action == ACTION_MKDIR)
    {
      operation->operation =
        operation->operation == OP_DELETE ? OP_REPLACE : OP_ADD;
      operation->kind = svn_node_dir;
    }
  /* Handle put operations (which can be adds, replacements, or opens). */
  else if (action == ACTION_PUT)
    {
      if (operation->operation == OP_DELETE)
        {
          operation->operation = OP_REPLACE;
        }
      else
        {
          SVN_ERR(eb->fetch_kind_func(&operation->kind, eb->fetch_kind_baton,
                                      relpath, scratch_pool));
          if (operation->kind == svn_node_file)
            operation->operation = OP_OPEN;
          else if (operation->kind == svn_node_none)
            operation->operation = OP_ADD;
          else
            return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                     "'%s' is not a file", relpath);
        }
      operation->kind = svn_node_file;
      operation->src_file = src_file;
    }
  else
    {
      /* We shouldn't get here. */
      SVN_ERR_MALFUNCTION();
    }

  return SVN_NO_ERROR;
}
Example #12
0
int main(int argc, char **argv)
{
    Operation operation; // operacie na vstupe, napr. select, min, max ...
    RangeFunction range_function; // range funkcia na vstupe, napr. row, col, ...
    int row_y0, row_y1, col_x0, col_x1 = -1; // pomocne premenne pre vyberove funkcie
    double double_tmp; // pomocna premenna pre typ double
    char word[MAX_LENGTH]; // obsah bunky
    int act_row = 1; // riadok, na ktorom sa momentalne nechadzam
    int act_col = 1; // stlpec, na ktorom sa momentalne nechadzam

    double result = 0.0; // priebezny a celkovy vysledok matematickych funkcii
    int count = 0; // pocet spracovanych cisel v matematickych funkciach
    int cell_in_area = FALSE; // kontrola ci sa nachadzam v zadanej oblasti


    if((strcmp("--help", argv[1]) == 0))  /* Ak je zadany parameter -- help tak vypise napovedu */
    {
    printf("%s", HELPMSG);
    return EXIT_SUCCESS;
    }
    /* Spracovanie vstupnych parametrov */
    if(argc == 1)
    {
        fprintf(stderr,"Nebol zadany ziadny argument, pre napovedu spustite program v tvare ./proj1 -- help\n"); // ak uzivatel nezada ziadny parameter tak mu vypise hlasenie
        return EXIT_FAILURE;
    }

    if (argc > 7)
      fprintf(stderr,"CHYBA zadal si prilis mnoho argumentov \n");

       // Operacia select, min, max ...
    if(get_operation(argv[1], &operation) == EXIT_FAILURE){
         fprintf(stderr,"ERROR, pre napovedu spustite program v tvare ./proj1 -- help\n");
        return EXIT_FAILURE;
    }
    if(argc < 2 + operation.required_parameters)
    {
        fprintf(stderr,"ERROR: Malo paramterov pre operaciu \n");
        return EXIT_FAILURE;
    }

    // Rozsah/vyber, napr. row, rows, col, ...
    if(get_range(argv[2], &range_function) == EXIT_FAILURE){
        fprintf(stderr,"ERROR \n");
        return EXIT_FAILURE;
    }


    if(argc < 3 + range_function.required_parameters)
    {
        printf("ERROR: Malo argumentov pre vyberovu funkciu \n");
        return EXIT_FAILURE;
    }
    /* Osetrenie vyberovych funkcii.
     Ak je pre vyberovu funkciu pozuitych vela argumentov, zoberiem prvy a ostatne ignorujem (napr.: `row 4 5', do row pojde 4 a 5 ignorujem). */
    switch(range_function.function)
    {
        case row:
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = (int) double_tmp;
                row_y1 = row_y0;
                col_x0 = -1;
                col_x1 = -1;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case col:
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = -1;
                row_y1 = -1;
                col_x0 = (int) double_tmp;
                col_x1 = col_x0;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case rows:
            col_x0 = -1;
            col_x1 = -1;
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = (int) double_tmp;
            }
            else
            {
               fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[4], &double_tmp) && (int) double_tmp > 0)
            {
                row_y1 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case cols:
            row_y0 = -1;
            row_y1 = -1;
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                col_x0 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[4], &double_tmp) && (int) double_tmp > 0)
            {
                col_x1 = (int) double_tmp;
            }
            else
            {
               fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case range:
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[4], &double_tmp) && (int) double_tmp > 0)
            {
                row_y1 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[5], &double_tmp) && (int) double_tmp > 0)
            {
                col_x0 = (int) double_tmp;
            }
            else
            {
               fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
               return EXIT_FAILURE;
            }
            if(is_number(argv[6], &double_tmp) && (int) double_tmp > 0)
            {
                col_x1 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        default:
            fprintf(stderr,"ERROR neznama akcias\n");
            return EXIT_FAILURE;
    }

    // Kontrola, ci su hranice rozsahov vyberovych funkcii OK
    if(row_y1 < row_y0)
    {
        fprintf(stderr,"ERROR:Index riadka Y musi byt vacsi ako index riadka X.\n");
        return EXIT_FAILURE;
    }
    
    if(col_x1 < col_x0)
    {
        fprintf(stderr,"ERROR:Index stlpca B musi byt vacsi ako index stlpca A.\n");
        return EXIT_FAILURE;
    }

    /* Spracovanie stdin.  Najprv zistim,ci sa bunka nachadza v pozadovanej oblasti a nasledne si nacitam jej obsah. 
     Citam bunku aj ked sa nenachadza v pozadovanej oblasti */
    while((cell_in_area = in_range(act_row, act_col, row_y0, row_y1, col_x0, col_x1), 
                get_cell_value(word, &act_row, &act_col) != EXIT_FAILURE))
    {
        if(cell_in_area) // ak sa bunka nachadza v pozadovanej oblasti, pokracujem v spracovani.
        {
            switch(operation.function)
            {
                case select:
                    if(operation_select(word) == EXIT_SUCCESS)
                        printf("\n"); 
                    else
                        return EXIT_FAILURE;
                    break;

                case min:
                    count++;
                    if(operation_min(word, &result, count) == EXIT_FAILURE)
                        return EXIT_FAILURE;
                    break;

                case max:
                    count++;
                    if(operation_max(word, &result, count) == EXIT_FAILURE)
                        return EXIT_FAILURE;
                    break;

                case sum:
                    if(operation_sum(word, &result) == EXIT_FAILURE)
                        return EXIT_FAILURE;
                    break;

                case avg:
                    count++;
                    if(operation_sum(word, &result) == EXIT_FAILURE)
                       return EXIT_FAILURE;
                    break;

                default:
                   fprintf(stderr,"ERROR:Neznama operacia\n");
                   return EXIT_FAILURE;
           }
        }

        // Ak dosiahnem hornu hranicu riadkov, koncim spracovanie.
        if(row_y1 != -1 && row_y1 < act_row){
            break;
        }
    }
    // Osetrenie vynimok pri vypise vysledku.
    switch(operation.function)
    {
        case select:
            // Nerobim nic, len aby som sa nedostal do default
            break;

        case avg:
            result /= (double) count;

        default:
            printf("%.10g", result);
            printf("\n");
    }
    return EXIT_SUCCESS;
}
Example #13
0
    // real dispatch
    static inline const std::string dispatch(symtab::world_map& universe, std::vector<std::string> const& message) {
      
      static void* jump_table[] = {
        &&undefined,               // 0
        &&do_vector,               // 1
        &&do_vectorz,              // 2
        &&do_vectorr,              // 3
        &&do_vectoru,              // 4
        &&do_superpose,            // 5
        &&do_subtract,             // 6
        &&do_neighbourhood,        // 7
        &&do_density,              // 8
        &&do_similarity,           // 9
        &&do_inner,                // 10
        &&do_terms,                // 11
        &&do_load,                 // 12
        &&do_train,                // 13
        &&do_lexicon,              // 14
        &&do_halt,                 // 15
        &&do_inner,                // 16
        &&do_countsum,             // 17
        &&do_distance,             // 18
        &&do_world,                // 19
        &&do_drop,                 // 20
        &&do_sparsity,             // 21
        &&do_mul,                  // 22
        &&do_save,                 // 23
        &&do_worlds,               // 24
        &&do_cardinality           // 25
      };
      
      // fail if we don't have a function name and a world context
      if (message.size() < 2) throw dispatch_error("invalid operation: rpc message too short");      
            
      // get world context
      symtab::world_map::world_t* world = universe.get_world(message[WORLD]);
      
      // lookup the function descriptor
      fd const& op = get_operation(message[1]);
      
      // validate args
      if (message.size() < op.arity_min || message.size() > op.arity_max)
        throw dispatch_error(message[FNAME] + ": wrong number of arguments");

      
      // i've always wanted to do this in c++ ;-)
      goto *jump_table[op.opcode];
      {
        
      undefined:
        throw dispatch_error("undefined function:" + message[FNAME]);
        
        
      do_vector: {
        return utl::format_double(world->ensure_symbol2(message[2], message[3], symtab::symbol::type::NOP, 0)->density(), "density");
      }
        
      do_vectorz: {
        return utl::format_double(world->ensure_symbol2(message[2], message[3], symtab::symbol::type::ZERO, 0)->density(), "density");
      }
        
      do_vectorr: {
        if (message.size() == 5) {
          char* end;
          const char* start = message[4].c_str();
          float p = strtof(start, &end);
          if (end == start || p < 0 || p > 1.) throw dispatch_error(message[FNAME] + ":sparsity not a valid real number in [0,1]");
          return utl::format_double(world->ensure_symbol2(message[2], message[3], symtab::symbol::type::RAND, p)->density(), "density");
        } else {
          return utl::format_double(world->ensure_symbol2(message[2], message[3], symtab::symbol::type::RAND)->density(), "density");
        }
      }
        
      do_vectoru: {
        return utl::format_double(world->ensure_symbol2(message[2], message[3], symtab::symbol::type::UNIT)->density(), "density");
      }
        
      do_superpose:
        return utl::format_double(world->add(message[2], message[3], message[4], message[5]), "density");
        
      do_subtract:
        return utl::format_double(world->sub(message[2], message[3], message[4], message[5]), "density");
        
      do_mul:
        return utl::format_double(world->mul(message[2], message[3], message[4], message[5]), "density");
        
        
      do_neighbourhood: {
        char* end;
        const char* start = message[4].c_str();
        float p = strtof(start, &end);
        if (end == start || p < 0 || p > 1.) throw dispatch_error(message[4] + " :sparsity not a valid real number in [0,1]");
        start = message[5].c_str();
        float d = strtof(start, &end);
        if (end == start || d < 0 || d > 1.) throw dispatch_error(message[5] + " :density not a valid real number in [0,1]");
        start = message[6].c_str();
        long n = strtol(start, &end, 10);
        if (end == start || n < 0) throw dispatch_error(message[6] + " :cardinality not a valid +ve integer");
        return utl::format_scores(world->neighbours(message[2], message[3], p, d, n));
      }
        
      do_density:
        return utl::format_double(world->get_density(message[2], message[3]), "density");
        
      do_similarity:
        return utl::format_double(world->similarity(message[2], message[3], message[4], message[5]), "similarity");
        
      do_inner:
        return utl::format_double(world->inner(message[2], message[3], message[4], message[5]), "inner");
        
      do_countsum:
        return utl::format_double(world->countsum(message[2], message[3], message[4], message[5]), "countsum");
        
      do_distance:
        return utl::format_double(world->distance(message[2], message[3], message[4], message[5]), "distance");
        
      do_terms:
        return utl::format_list(world->get_names(message[2]), "terms");
        
      do_load:
        world->restore();
        return utl::format_string(world->name, "worldname");
        
      do_train:
        throw dispatch_error("unimplemented function: " + message[FNAME]);
        //return utl::format_string(world->load_tuples(message[2]), "path");
        
      do_lexicon:
        return utl::format_string(world->load_lexicon(message[2]), "path");
        
      do_world: {
        char* end;
        const char* start = message[3].c_str();
        long n = strtol(start, &end, 10);
        if (end == start || n < 0) throw dispatch_error(message[3] + " :reservation not a +ve integer");
        universe.make_world(message[2],  n, universe);
        return utl::format_string(message[2], "worldname");
      }
        
      do_drop: {
        universe.delete_world(message[2]);
        return utl::format_string(message[2], "worldname");
      }
        
      do_sparsity: {
        char* end;
        const char* start = message[2].c_str();
        float p = strtof(start, &end);
        if (end == start || p < 0 || p > 1.) throw dispatch_error(message[2] + ":sparsity not a real number in [0,1]");
        world->set_sparsity(p);
        return utl::format_double(world->standard_sparsity, "sparsity");
      }
        
      do_halt:
        throw user_abort("halted");
      }
      
      do_save: {
        world->save();
        return utl::format_string(world->name, "worldname");
      }

      do_cardinality: {
        return utl::format_integer(universe.get_world(message[2])->cardinality(), "cardinality");
      }

      do_worlds: {
        return utl::format_list(universe.get_worlds(), "worldnames");
      }
    }
  };
// funzione per creare una transazione ed accodarla
transaction_descriptor *create_new_synthetic_transaction(state_type *state, int tx_id, double data_items_zipf_const) {

	// Get the client configuration from simulation state
	CLIENT_lp_state_type *pointer = &state->type.client_state;
	operation_descriptor *op = NULL;
	int number_of_operations = 0;
	int i, j;
	int tx_class_id = -1;
	double val;
	int local_access;
	transaction_descriptor *tx_descr = (transaction_descriptor *) malloc(sizeof(transaction_descriptor));

	tx_descr->tx_id = tx_id;
	tx_descr->next = NULL;
	tx_descr->first_operation = NULL;
	tx_descr->last_operation = NULL;
	tx_descr->current_operation = NULL;

	if (pointer->configuration.tlm_verbose) {
		printf("creazione nuova transazione tx_id %i\n", tx_id);
	}

	//crea le operazioni
	// seleziona la classe transazionale
	double rand_number = Random();
	float sum = 0;

	for (i = 0; i < pointer->configuration.number_of_tx_classes; i++) {
		sum += pointer->configuration.tx_class_probability[i];
		if (rand_number < sum) {
			tx_class_id = i;
			break;
		}
	}

	tx_descr->tx_class_id = tx_class_id;

	// seleziona la lunghezza delle transazioni in operazioni
	switch (pointer->configuration.transaction_length_type) {
	case FIXED:
		number_of_operations = pointer->configuration.tx_class_length[tx_class_id];
		//number_of_operations=5; //TODO rimettere la lungezza delle transazioni in modo corretto
		break;
	case UNIFORM:
		//number_of_operations=5;
		number_of_operations = RandomRange(0, pointer->configuration.tx_class_length[tx_class_id] - 1) + 1;
		break;
	case ZIPF:
	case SINGLE_BAR:
	default:
		fprintf(stderr, "Unsupported value %d at %s:%d\n", pointer->configuration.transaction_length_type, __FILE__, __LINE__);
	}

	for (j = 1; j <= number_of_operations; j++) {
		if (pointer->configuration.tlm_verbose) {
			printf("\tcreo operazione %i\n", j);
		}

		//crea l'operazione
		op = (operation_descriptor *) malloc(sizeof(operation_descriptor));
		op->op_number = j;
		// seleziona il tipo di accesso
		double r;
		do {
			r = Random();
		} while (r == 1);

		if (r <= pointer->configuration.tx_class_write_probability[tx_class_id]) {
			op->op_type = TX_PUT;
		} else {
			op->op_type = TX_GET;
		}

		operation_descriptor *l;

		//selezione distribuzione accesso ai data items
		//TODO

		switch (pointer->configuration.object_access_distribution_type[tx_class_id]) {
		//int dist=UNIFORM;
		//switch (dist) {

		case UNIFORM:

			// seleziona #pointer->cache_objects diversi
			do {
				op->object_key_id = RandomRange(0, state->cache_objects - 1);
				l = get_operation(tx_descr, op->object_key_id);
			} while (l);

			break;

		case LOCALITY:

			local_access=0;
			do {
				r = Random();
			} while (r == 1);
			if (r <= 1) {
				local_access=1;
			}
			do {
				do {
					op->object_key_id = RandomRange(0, state->cache_objects - 1);
					l = get_operation(tx_descr, op->object_key_id);
				} while (l);
			} while (
					local_access && !is_owner(op->object_key_id, get_server(state), state->num_servers, state->num_clients, state->object_replication_degree)
					||
					!local_access && is_owner(op->object_key_id, get_server(state), state->num_servers, state->num_clients, state->object_replication_degree)
			);



			break;

		case TOPKEYS:

			rand_number = Random();
			//printf("Random: %f\n", rand_number);
			float * objects_access_probability;
			op->object_key_id = -1;
			int id_item;
			int number_of_top_keys = 0;
			long double no_tk_probability;
			long double sum_tk = 0;
			bool top_key = false;

			//printf("%d - %d\n",op->op_type, TX_PUT);
			if (op->op_type == TX_GET) {
				objects_access_probability = pointer->configuration.topkeys_cache_objects_get_probability;
				number_of_top_keys = pointer->configuration.number_of_gets_topkeys;
			} else {
				objects_access_probability = pointer->configuration.topkeys_cache_objects_put_probability;
				number_of_top_keys = pointer->configuration.number_of_puts_topkeys;
			}

			for (id_item = 0; id_item < number_of_top_keys; id_item++) {
				sum_tk += objects_access_probability[id_item];
				//printf("sum: %f\n",sum);

				if (rand_number < sum_tk) {
					top_key = true;
					op->object_key_id = id_item;
					break;
				}
			}

			if (!top_key) {

				no_tk_probability = (1 - sum_tk) / (state->cache_objects - number_of_top_keys);

				for (; id_item < state->cache_objects; id_item++) {
					sum_tk += no_tk_probability;
					//printf("sum-no_tk: %f\n",sum);

					if (rand_number < sum_tk) {
						op->object_key_id = id_item;
						break;
					}
				}
			}

			break;

			//printf("Scelto: %d\n",op->object_key_id);

		case ZIPF:

			op->object_key_id = Zipf(data_items_zipf_const, state->cache_objects);

			break;

		case SINGLE_BAR:

			val = Random();

			if (val < 0.8) { // TODO: Alessandro: parametrizzare in una macro?!
				op->object_key_id = RandomRange(0, 10 - 1); //TODO va sul 20% dei data_item
			} else {
				op->object_key_id = RandomRange(0, state->cache_objects - 10 - 1) + 10; //restante 80%
			}

			break;
		}

		if (pointer->configuration.tlm_verbose) {
			printf("\t\ttipo %i\n", op->op_type);
			printf("\t\tdata_item %i\n", op->object_key_id);
		}

		op->next = NULL;
		enqueue_operation(tx_descr, op);
	}

	//resetta lo stato della transazione
	reset_transaction_state(tx_descr);

	return tx_descr;
}
Example #15
0
/* Add PATH to the operations tree rooted at OPERATION, creating any
   intermediate nodes that are required.  Here's what's expected for
   each action type:

      ACTION          URL    REV      SRC-FILE  PROPNAME
      ------------    -----  -------  --------  --------
      ACTION_MKDIR    NULL   invalid  NULL      NULL
      ACTION_CP       valid  valid    NULL      NULL
      ACTION_PUT      NULL   invalid  valid     NULL
      ACTION_RM       NULL   invalid  NULL      NULL
      ACTION_PROPSET  valid  invalid  NULL      valid
      ACTION_PROPDEL  valid  invalid  NULL      valid

   Node type information is obtained for any copy source (to determine
   whether to create a file or directory) and for any deleted path (to
   ensure it exists since svn_delta_editor_t->delete_entry doesn't
   return an error on non-existent nodes). */
static svn_error_t *
build(action_code_t action,
      const char *path,
      const char *url,
      svn_revnum_t rev,
      const char *prop_name,
      const char *prop_value,
      const char *src_file,
      svn_revnum_t head,
      const char *anchor,
      svn_ra_session_t *session,
      struct operation *operation,
      apr_pool_t *pool)
{
  apr_array_header_t *path_bits = svn_path_decompose(path, pool);
  const char *path_so_far = "";
  const char *copy_src = NULL;
  svn_revnum_t copy_rev = SVN_INVALID_REVNUM;
  int i;

  /* Look for any previous operations we've recognized for PATH.  If
     any of PATH's ancestors have not yet been traversed, we'll be
     creating OP_OPEN operations for them as we walk down PATH's path
     components. */
  for (i = 0; i < path_bits->nelts; ++i)
    {
      const char *path_bit = APR_ARRAY_IDX(path_bits, i, const char *);
      path_so_far = svn_path_join(path_so_far, path_bit, pool);
      operation = get_operation(path_so_far, operation, pool);

      /* If we cross a replace- or add-with-history, remember the
      source of those things in case we need to lookup the node kind
      of one of their children.  And if this isn't such a copy,
      but we've already seen one in of our parent paths, we just need
      to extend that copy source path by our current path
      component. */
      if (operation->url
          && SVN_IS_VALID_REVNUM(operation->rev)
          && (operation->operation == OP_REPLACE
              || operation->operation == OP_ADD))
        {
          copy_src = subtract_anchor(anchor, operation->url, pool);
          copy_rev = operation->rev;
        }
      else if (copy_src)
        {
          copy_src = svn_path_join(copy_src, path_bit, pool);
        }
    }

  /* Handle property changes. */
  if (prop_name)
    {
      if (operation->operation == OP_DELETE)
        return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                 "cannot set properties on a location being"
                                 " deleted ('%s')", path);
      SVN_ERR(svn_ra_check_path(session,
                                copy_src ? copy_src : path,
                                copy_src ? copy_rev : head,
                                &operation->kind, pool));
      if (operation->kind == svn_node_none)
        return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                 "propset: '%s' not found", path);
      else if ((operation->kind == svn_node_file)
               && (operation->operation == OP_OPEN))
        operation->operation = OP_PROPSET;
      apr_table_set(operation->props, prop_name, prop_value);
      if (!operation->rev)
        operation->rev = rev;
      return SVN_NO_ERROR;
    }

  /* We won't fuss about multiple operations on the same path in the
     following cases:

       - the prior operation was, in fact, a no-op (open)
       - the prior operation was a propset placeholder
       - the prior operation was a deletion

     Note: while the operation structure certainly supports the
     ability to do a copy of a file followed by a put of new contents
     for the file, we don't let that happen (yet).
  */
  if (operation->operation != OP_OPEN
      && operation->operation != OP_PROPSET
      && operation->operation != OP_DELETE)
    return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                             "unsupported multiple operations on '%s'", path);

  /* For deletions, we validate that there's actually something to
     delete.  If this is a deletion of the child of a copied
     directory, we need to remember to look in the copy source tree to
     verify that this thing actually exists. */
  if (action == ACTION_RM)
    {
      operation->operation = OP_DELETE;
      SVN_ERR(svn_ra_check_path(session,
                                copy_src ? copy_src : path,
                                copy_src ? copy_rev : head,
                                &operation->kind, pool));
      if (operation->kind == svn_node_none)
        {
          if (copy_src && strcmp(path, copy_src))
            return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                     "'%s' (from '%s:%ld') not found",
                                     path, copy_src, copy_rev);
          else
            return svn_error_createf(SVN_ERR_BAD_URL, NULL, "'%s' not found",
                                     path);
        }
    }
  /* Handle copy operations (which can be adds or replacements). */
  else if (action == ACTION_CP)
    {
      if (rev > head)
        return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
                                "Copy source revision cannot be younger "
                                "than base revision");
      operation->operation =
        operation->operation == OP_DELETE ? OP_REPLACE : OP_ADD;
      if (operation->operation == OP_ADD)
        {
          /* There is a bug in the current version of mod_dav_svn
             which incorrectly replaces existing directories.
             Therefore we need to check if the target exists
             and raise an error here. */
          SVN_ERR(svn_ra_check_path(session,
                                    copy_src ? copy_src : path,
                                    copy_src ? copy_rev : head,
                                    &operation->kind, pool));
          if (operation->kind != svn_node_none)
            {
              if (copy_src && strcmp(path, copy_src))
                return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                         "'%s' (from '%s:%ld') already exists",
                                         path, copy_src, copy_rev);
              else
                return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                         "'%s' already exists", path);
            }
        }
      SVN_ERR(svn_ra_check_path(session, subtract_anchor(anchor, url, pool),
                                rev, &operation->kind, pool));
      if (operation->kind == svn_node_none)
        return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                 "'%s' not found",
                                  subtract_anchor(anchor, url, pool));
      operation->url = url;
      operation->rev = rev;
    }
  /* Handle mkdir operations (which can be adds or replacements). */
  else if (action == ACTION_MKDIR)
    {
      operation->operation =
        operation->operation == OP_DELETE ? OP_REPLACE : OP_ADD;
      operation->kind = svn_node_dir;
    }
  /* Handle put operations (which can be adds, replacements, or opens). */
  else if (action == ACTION_PUT)
    {
      if (operation->operation == OP_DELETE)
        {
          operation->operation = OP_REPLACE;
        }
      else
        {
          SVN_ERR(svn_ra_check_path(session,
                                    copy_src ? copy_src : path,
                                    copy_src ? copy_rev : head,
                                    &operation->kind, pool));
          if (operation->kind == svn_node_file)
            operation->operation = OP_OPEN;
          else if (operation->kind == svn_node_none)
            operation->operation = OP_ADD;
          else
            return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                     "'%s' is not a file", path);
        }
      operation->kind = svn_node_file;
      operation->src_file = src_file;
    }
  else
    {
      /* We shouldn't get here. */
      abort();
    }

  return SVN_NO_ERROR;
}
TIMESTAMP complex_assert::commit(TIMESTAMP t1, TIMESTAMP t2)
{
	// handle once mode
	if ( once==ONCE_TRUE)
	{
		once_value = value;
		once = ONCE_DONE;
	} 
	else if ( once==ONCE_DONE)
	{
		if ( once_value.Re()==value.Re() && once_value.Im()==value.Im() )
		{
			gl_verbose("Assert skipped with ONCE logic");
			return TS_NEVER;
		} 
		else 
		{
			once_value = value;
		}
	}

	// get the target property
	gld_property target_prop(get_parent(),get_target());
	if ( !target_prop.is_valid() || target_prop.get_type()!=PT_complex ) {
		gl_error("Specified target %s for %s is not valid.",get_target(),get_parent()->get_name());
		/*  TROUBLESHOOT
		Check to make sure the target you are specifying is a published variable for the object
		that you are pointing to.  Refer to the documentation of the command flag --modhelp, or 
		check the wiki page to determine which variables can be published within the object you
		are pointing to with the assert function.
		*/
		return 0;
	}

	// test the target value
	complex x; target_prop.getp(x);
	if ( status==ASSERT_TRUE )
	{
		if ( operation==FULL || operation==REAL || operation==IMAGINARY )
		{	
			complex error = x - value;
			double real_error = error.Re();
			double imag_error = error.Im();
			if ( ( _isnan(real_error) || fabs(real_error)>within ) 
				&& ( operation==FULL || operation==REAL )
				)
			{
				gl_error("Assert failed on %s: real part of %s %g not within %f of given value %g", 
					get_parent()->get_name(), get_target(), x.Re(), within, value.Re());
				return 0;
			}
			if ( ( _isnan(imag_error) || fabs(imag_error)>within ) 
				&& ( operation==FULL || operation==IMAGINARY )
				)
			{
				gl_error("Assert failed on %s: imaginary part of %s %+gi not within %f of given value %+gi", 
					get_parent()->get_name(), get_target(), x.Im(), within, value.Im());
				return 0;
			}
		}
		else if ( operation==MAGNITUDE )
		{
			double magnitude_error = x.Mag() - value.Mag();
			if ( _isnan(magnitude_error) || fabs(magnitude_error)>within )
			{
				gl_error("Assert failed on %s: Magnitude of %s (%g) not within %f of given value %g", 
					get_parent()->get_name(), get_target(), x.Mag(), within, value.Mag());
				return 0;
			}
		}
		else if (get_operation() == ANGLE)
		{
			double angle_error = x.Arg() - value.Arg();
			if ( _isnan(angle_error) || fabs(angle_error)>within )
			{
				gl_error("Assert failed on %s: Angle of %s (%g) not within %f of given value %g", 
					get_parent()->get_name(), get_target(), x.Arg(), within, value.Arg());
				return 0;
			}
		}
	}
	else if (get_status() == ASSERT_FALSE)
	{
		complex error = x - value;
		double real_error = error.Re();
		double imag_error = error.Im();
		if ( ( _isnan(real_error) || fabs(real_error)<within )
			|| ( _isnan(imag_error) || fabs(imag_error)<within )
			)
		{
			if ( _isnan(real_error) || fabs(real_error)<within ) 
			{
				gl_error("Assert failed on %s: real part of %s %g is within %f of %g", 
					get_parent()->get_name(), get_target(), x.Re(), within, value.Re());
			}
			if ( _isnan(imag_error) || fabs(imag_error)<within ) {
				gl_error("Assert failed on %s: imaginary part of %s %+gi is within %f of %gi", 
					get_parent()->get_name(), get_target(), x.Im(), within, value.Im());
			}
			return 0;
		}
	}
	else
	{
		gl_verbose("Assert test is not being run on %s", get_parent()->get_name());
		return TS_NEVER;
	}
	gl_verbose("Assert passed on %s",get_parent()->get_name());
	return TS_NEVER;
}
int main(int argc, char **argv)
{
   int operation;

   g_type_init();
   ecore_init();
   if(argc < 2) {
      fprintf(stderr, "1:set(db), 2:set(file), 3:set(memory), 4:set(gconf_d), 5:set(gconf_l) \n");
      fprintf(stderr, "6:get(db), 7:get(file), 8:get(memory), 9:get(gconf_d), 10:get(gconf_l) \n");
      fprintf(stderr, "11:unset(db), 12:unset(file), 13:unset(memory), 14:unset(gconf_d), 15:unset(gconf_l) \n");
      return -1;
   }

   operation = atoi(argv[1]);
   switch(operation)
   {
      case 1:
         set_operation(0);
         break;
      case 2:
         set_operation(1);
         break;
      case 3:
         set_operation(2);
         break;
      case 4:
         set_operation(3);
         break;
      case 5:
         set_operation(4);
         break;
      case 6:
         get_operation(0, "db/timetest");
         break;
      case 7:
         get_operation(1, "file/timetest");
         break;
      case 8:
         get_operation(2, "memory/timetest");
         break;
      case 9:
         get_operation(3, "gconf_l/timetest");
         break;
      case 10:
         get_operation(4, "gconf_d/timetest");
         break;
      case 11:
         unset_operation(0);
         break;
      case 12:
         unset_operation(1);
         break;
      case 13:
         unset_operation(2);
         break;
      case 14:
         unset_operation(3);
         break;
      case 15:
         unset_operation(4);
         break;
      case 16:
         vconf_notify_key_changed(vconfkeys[0][1], test_cb2, NULL);
         vconf_notify_key_changed(vconfkeys[1][1], test_cb2, NULL);
         vconf_notify_key_changed(vconfkeys[2][1], test_cb2, NULL);
         vconf_notify_key_changed(vconfkeys[3][1], test_cb2, NULL);
         vconf_notify_key_changed(vconfkeys[4][1], test_cb2, NULL);

         //ecore_main_loop_begin();
         GMainLoop *event_loop;
         event_loop = g_main_loop_new(NULL, FALSE);
         g_main_loop_run(event_loop);
         break;
   }

   return 0;
}