Ejemplo n.º 1
0
void get_put_vars(int exo_file, ex_entity_type type, int num_blocks, int num_vars,
                  int num_time_steps, const std::vector<int> &num_per_block, const char* mname)

{
  /* truth table */
  if (debug) logger("\tTruth Table");
  std::vector<int> truth_table(num_vars*num_blocks);
  ex_get_truth_table(exo_file, type, num_blocks, num_vars,TOPTR(truth_table));

  size_t num_entity = std::accumulate(num_per_block.begin(), num_per_block.end(), 0);
  std::vector<double> scr(num_entity * num_time_steps);

  std::vector<int> ids(num_blocks);
  ex_get_ids(exo_file, type, TOPTR(ids));

  char str[32];
  for (int i=0; i < num_vars; i++) {
    if (debug) logger("\tReading");
    std::fill(scr.begin(), scr.end(), 0.0);
    size_t n=0;
    sprintf(str,mname,i+1);
    for (int j=0; j<num_time_steps; j++){
      for (int k=0; k<num_blocks; k++){
        if (truth_table[num_vars*k+i]==1) {
          ex_get_var(exo_file,j+1,type, i+1,ids[k],num_per_block[k],&scr[n]);
        }
        n=n+num_per_block[k];
      }
    }
    if (debug) logger("\tWriting");
    PutDbl(str,num_entity,num_time_steps,TOPTR(scr));
  }
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
    int i, j, output;
    int test;
    char combinestr[100] = "(";
    if(argc == 1) {
        printf("Logical Expression 1 :\n");
        get_expression(ipstr);
        truth_table(ipstr, fnvalues1, &numvar);

        strcat(combinestr, ipstr);
        strcat(combinestr, "=");
        printf("\nLogical Expression 2 :\n");
        get_expression(ipstr);
        truth_table(ipstr, fnvalues2, &numvar);
        strcat(combinestr, ipstr);
        strcat(combinestr, ")");

        truth_table(combinestr, fnvalues1, &numvar);

        test = test_for_tautology(fnvalues1, numvar);
        if(test == 1)
            printf("\nThe given functions are equivalent!\n");
        else
            printf("\nThe given functions are NOT equivalent!\n");
    }
    else if(argc != 3) {
        printf("Please enter exactly two logical expressions!");
        return 0;
    }
    else {
        printf("Logical Expression 1 :\n");
        strcpy(ipstr, argv[1]);
        truth_table(ipstr, fnvalues1, &numvar);

        strcat(combinestr, ipstr);
        strcat(combinestr, "=");
        printf("\nLogical Expression 2 :\n");
        strcpy(ipstr, argv[2]);
        truth_table(ipstr, fnvalues2, &numvar);
        strcat(combinestr, ipstr);
        strcat(combinestr, ")");

        truth_table(combinestr, fnvalues1, &numvar);

        test = test_for_tautology(fnvalues1, numvar);
        if(test == 1)
            printf("\nThe given functions are equivalent!\n");
        else
            printf("\nThe given functions are NOT equivalent!\n");

    }

    return 0;
}