Exemplo n.º 1
0
void getSearchSpaceRange(int dimensions, double **minSearchSpace, double **maxSearchSpace)
{

  int i;
  int result;
  double dmin,dmax;
  PlTerm min,max;
  PlTerm args[3];

  for( i=0; i<dimensions; i++){

    Pl_Query_Begin(TRUE);
    min=Mk_Variable();
    max=Mk_Variable();
    args[0]=Mk_Integer(i);
    args[1]=min;
    args[2]=max;
    result=Pl_Query_Call(Find_Atom("fssbounds"),3,args);
    dmin=Rd_Float_Check(args[1]);
    dmax=Rd_Float_Check(args[2]);
    (*minSearchSpace)[i] = (double)dmin;
    (*maxSearchSpace)[i] = (double)dmax;

    if (debug == TRUE) {
		printf("dimension: %d :: dmin : %f dmax : %f\n",i,dmin,dmax);
		fflush(NULL);
    }
    Pl_Query_End(PL_RECOVER);

  }

}
Exemplo n.º 2
0
int aslAddBindingStatement( AsSystem s, AsMediaAddress m, AsNetworkAddress n, AsTime t ) {

    // Check if the logic layer is disabled
    if (aslDisableLogicFlag == 1)
	return 0;

    // Local variables
    PlTerm arg[10];
    PlTerm arg2[10];
    PlBool res;

    // Start processing, if needed 
    if ( ! aslogic_initialized ) aslInitLogic();

    // Do the GPC query
    Pl_Query_Begin(PL_TRUE);
    arg[0] = Pl_Mk_String(s);
    arg[1] = Pl_Mk_String(n);
    arg[2] = Pl_Mk_String(m);
    arg[3] = Pl_Mk_Integer(t);
    arg2[0] = Pl_Mk_Callable(gpc_func_dynamic_binding_statement_num, 4, arg);
    res = Pl_Query_Call(gpc_func_asserta_num, 1, arg2);
    Pl_Query_End(PL_KEEP_FOR_PROLOG);

    // Get output and process
    if (res != 1) {
	asLogMessage( "Prolog launch failed, aborting." );
	exit( -1 );
    }
    asLogMessage( "Binding statement added successfully (%s,%lu)", s, t );

    // Return successfully
    return( 0 );
}
Exemplo n.º 3
0
int is_feasible_Fitness(double const *x) {

	int i;
	int res = 1;
	int result;
	double dmin, dmax;
	PlTerm min, max;
	PlTerm args[3];

	int DIM = (int) (x[-1]);
	for (i = 0; i < DIM; i++) {

		Pl_Query_Begin(TRUE);
		min = Mk_Variable();
		max = Mk_Variable();
		args[0] = Mk_Integer(i);
		args[1] = min;
		args[2] = max;
		result = Pl_Query_Call(Find_Atom("bounds"), 3, args);
		dmin = Rd_Float_Check(args[1]);
		dmax = Rd_Float_Check(args[2]);
		//printf("dmin : %f dmax : %f xi : %f\n",dmin,dmax,x[i]);
		if ((x[i] < dmin) || (x[i] > dmax))
			res = 0;
		Pl_Query_End(PL_RECOVER);

	}
	return res;
}
Exemplo n.º 4
0
void set_random_paramsFss(int dim) {

	PlTerm args[1];
	int result;

	Pl_Query_Begin(TRUE);
	args[0] = Mk_Integer(dim);

	result = Pl_Query_Call(Find_Atom("fss_restart"), 1, args);

	Pl_Query_End(PL_RECOVER);

}
Exemplo n.º 5
0
int aslFindValidNetworkBinding( AsNetworkAddress n, AsMediaAddress m, AsTime t )  {

    // Check if the logic layer is disabled
    if (aslDisableLogicFlag == 1)
        return 0;

    // Local variables
    int i;
    int sol_num = 0;
    PlTerm arg[10];
    char *sol[GPC_MAX_SOLUTION_NUM];
    PlBool res;

    // Start processing, if needed 
    if ( ! aslogic_initialized ) aslInitLogic();

    // Do the GPC query
    Pl_Query_Begin(PL_TRUE);
    arg[0] = Pl_Mk_Variable();
    arg[1] = Pl_Mk_String(m);
    arg[2] = Pl_Mk_Integer(t);
    res = Pl_Query_Call(gpc_func_valid_binding_num, 3, arg);
    while (res)
    {
	sol[sol_num++] = Pl_Rd_String(arg[0]);
	res = Pl_Query_Next_Solution();
	if (sol_num >= GPC_MAX_SOLUTION_NUM)
	{
		asLogMessage("Error: aslFindValidNetworkBinding got more than [%d] solutions - searching stopped",
				GPC_MAX_SOLUTION_NUM);
		break;
	}
    }
    Pl_Query_End(PL_KEEP_FOR_PROLOG);

    // Parse out the solutions
    asLogMessage("Info: aslFindValidNetworkBinding got [%d] solutions in total", sol_num);
    for (i = 0; i < sol_num; i++)
    {
	// Copy and remove trailing space
	strncpy( n, sol[i], MAX_NETADDR_LENGTH );
	asLogMessage( "Find valid network binding successfully (%s,%lu)->[%s]", m, t, n );

	// Return we found it - currently is the first solution we have found
	return( 1 );
    }

    // Return successfully
    return( 0 );
}
Exemplo n.º 6
0
/*-------------------------------------------------------------------------*
 * MAIN                                                                    *
 *                                                                         *
 * See comments in EnginePl/main.c about the use of the wrapper function.  *
 *-------------------------------------------------------------------------*/
static int
Main_Wrapper(int argc, char *argv[])
{
  int func;
  PlTerm arg[10];
  char str[100];
  char *sol[100];
  int i, nb_sol = 0;
  PlBool res;

  Pl_Start_Prolog(argc, argv);

  func = Pl_Find_Atom("anc");
  for (;;)
    {
      printf("\nEnter a name (or 'end' to finish): ");
      fflush(stdout);
      if (scanf("%s", str))	/* avoid gcc warning warn_unused_result */
	;

      if (strcmp(str, "end") == 0)
	break;

      Pl_Query_Begin(PL_TRUE);

      arg[0] = Pl_Mk_Variable();
      arg[1] = Pl_Mk_String(str);
      nb_sol = 0;
      res = Pl_Query_Call(func, 2, arg);
      while (res)
	{
	  sol[nb_sol++] = Pl_Rd_String(arg[0]);
	  res = Pl_Query_Next_Solution();
	}
      Pl_Query_End(PL_RECOVER);

      for (i = 0; i < nb_sol; i++)
	printf("  solution: %s\n", sol[i]);
      printf("%d solution(s)\n", nb_sol);
    }

  Pl_Stop_Prolog();
  return 0;
}
Exemplo n.º 7
0
/*-------------------------------------------------------------------------*
 * MY_CALL                                                                 *
 *                                                                         *
 *-------------------------------------------------------------------------*/
PlBool
my_call(PlTerm goal)
{
  PlTerm *args;
  int functor, arity;
  int result;

  args = Pl_Rd_Callable_Check(goal, &functor, &arity);
  Pl_Query_Begin(PL_FALSE);
  result = Pl_Query_Call(functor, arity, args);
  Pl_Query_End(PL_KEEP_FOR_PROLOG);
  if (result == PL_EXCEPTION)
    {
      PlTerm except = Pl_Get_Exception();
      Pl_Exec_Continuation(Pl_Find_Atom("throw"), 1, &except);
    }

  return result;
}
Exemplo n.º 8
0
/* ----------------------------------------------------------------------- */
double f_biochamFss(double const *x, int dimensions) {
	if (debug == TRUE) {
		printf("f_biochamFss\n"); /* positions:: %p\n", x);*/
		fflush(NULL);
	}
	int i;
	double dist = 0.00001;
	int DIM = dimensions;//(int) (x[-1]);
	PlTerm plist[DIM];
	PlTerm cost;
	PlTerm args[2];
	int result;

	Pl_Query_Begin(TRUE);
	/*make vars */

	cost = Mk_Variable();
	for (i = 0; i < DIM; ++i) {
		if (debug == TRUE) {
			printf("f_biochamFss:: position values: %f \n",x[i]);
			fflush(NULL);
		}
		plist[i] = Mk_Float(x[i]);
	}

	args[0] = Mk_Proper_List(DIM, plist);
	args[1] = cost;

	result = Pl_Query_Call(Find_Atom("distance_fss"), 2, args);

	dist = Rd_Float_Check(args[1]);

	if (debug == TRUE) {
		printf("f_biochamFss:: dist is infinity: %d \n", ((dist == INFINITY || dist == -INFINITY)?1:0) );
		printf("f_biochamFss:: dist: %f \n",dist);
		fflush(NULL);
	}

	Pl_Query_End(PL_RECOVER);

	return dist;
}
Exemplo n.º 9
0
/* ----------------------------------------------------------------------- */
double f_biocham_multiFss(double const *x, int dimensions) {

	int i;
	double dist = 0.;
	int DIM = dimensions;//(int) (x[-1]);
	PlTerm plist[DIM];
	PlTerm cost;
	PlTerm args[2];
	int result;

	Pl_Query_Begin(TRUE);
	/*make vars */

	cost = Mk_Variable();
	for (i = 0; i < DIM; ++i) {

			printf("f_biochamFssMulti:: position values: %f \n",x[i]);
			fflush(NULL);

		plist[i] = Mk_Float(x[i]);
	}
	args[0] = Mk_Proper_List(DIM, plist);
	args[1] = cost;

		printf("f_biochamFssMulti:: chamando a func multi \n");
		fflush(NULL);

	result = Pl_Query_Call(Find_Atom("distance_fss_multi"), 2, args);

		printf("f_biochamFssMulti:: retornando da fun�‹o :: result %d\n", result);
		fflush(NULL);

	dist = Rd_Float_Check(args[1]);

	printf("f_biochamFssMulti:: dist: %f \n", dist);
	fflush(NULL);
	Pl_Query_End(PL_RECOVER);

	// printf("cdone\n");
	return dist;
}
Exemplo n.º 10
0
/*-------------------------------------------------------------------------*
 * ALL_OP                                                                  *
 *                                                                         *
 *-------------------------------------------------------------------------*/
PlBool
all_op(PlTerm list)
{
  PlTerm op[1024];
  PlTerm args[3];
  int n = 0;
  int result;

  Pl_Query_Begin(PL_TRUE);
  args[0] = Pl_Mk_Variable();
  args[1] = Pl_Mk_Variable();
  args[2] = Pl_Mk_Variable();
  result = Pl_Query_Call(Pl_Find_Atom("current_op"), 3, args);
  while (result)
    {
      op[n++] = Pl_Mk_Atom(Pl_Rd_Atom(args[2])); /* arg #2 is the name of the op */
      result = Pl_Query_Next_Solution();
    }
  Pl_Query_End(PL_RECOVER);

  return Pl_Un_Proper_List_Check(n, op, list);
}
Exemplo n.º 11
0
int aslSystemTrusted( AsSystem s, AsTime t ) {

    // Check if the logic layer is disabled
    if (aslDisableLogicFlag == 1)
	return 0;

    // Local variables
    PlTerm arg[10];
    PlBool res;

    // Start processing, if needed 
    if ( ! aslogic_initialized ) aslInitLogic();

    // Do the GPC query
    Pl_Query_Begin(PL_TRUE);
    arg[0] = Pl_Mk_String(s);
    arg[1] = Pl_Mk_Integer(t);
    res = Pl_Query_Call(gpc_func_trusted_num, 2, arg);
    Pl_Query_End(PL_KEEP_FOR_PROLOG);

    // Just reture the res!
    return( res );
}
Exemplo n.º 12
0
int simulFss(double const *x, int DIM) {
	int i;
	PlTerm plist[DIM];
	PlTerm args[1];
	int result;

	if (debug == TRUE) {
		printf("simulFSS:: graph plot \n");
		fflush(NULL);
	}
	Pl_Query_Begin(TRUE);
	/*make vars */

	for (i = 0; i < DIM; ++i) {
		plist[i] = Mk_Float(x[i]);
	}
	args[0] = Mk_Proper_List(DIM, plist);

	result = Pl_Query_Call(Find_Atom("simul_fss"), 1, args);

	Pl_Query_End(PL_RECOVER);

	return 1;
}
Exemplo n.º 13
0
static int Main_Wrapper(int argc, char *argv[]) {
	int func;
	PlTerm arg[3];
	PlBool res;

	/*****************************************************************/
	int not;
	int and;
	int or;
	int says;
	int implies;
	int colon;
	int geq;
	PlTerm plterm_0;
	PlTerm plterm_1[2];
	PlTerm plterm_2;
	PlTerm plterm_3[2];
	PlTerm plterm_4;
	PlTerm plterm_5[2];
	PlTerm plterm_6;
	PlTerm plterm_7[2];
	PlTerm plterm_8;
	PlTerm plterm_9[2];
	PlTerm plterm_10;
	PlTerm plterm_11[2];
	PlTerm plterm_12;
	PlTerm plterm_13;
	PlTerm plterm_14[2];
	PlTerm plterm_15;
	PlTerm plterm_16;
	PlTerm plterm_17;
	PlTerm plterm_18[2];
	PlTerm plterm_19;
	PlTerm plterm_20;
	PlTerm plterm_21;
	PlTerm plterm_22[2];
	PlTerm plterm_23;
	PlTerm plterm_24[2];
	PlTerm plterm_25;
	PlTerm plterm_26[2];
	PlTerm plterm_27;
	PlTerm plterm_28;
	PlTerm plterm_29;
	PlTerm plterm_30;
	PlTerm plterm_31;
	PlTerm plterm_32[2];
	PlTerm plterm_33;
	PlTerm plterm_34[2];
	PlTerm plterm_35;
	PlTerm plterm_36;
	PlTerm plterm_37;
	PlTerm plterm_38[2];
	PlTerm plterm_39;
	PlTerm plterm_40[2];
	PlTerm plterm_41;
	PlTerm plterm_42;
	PlTerm plterm_43[2];
	PlTerm plterm_44;
	PlTerm plterm_45;
	PlTerm plterm_46;
	PlTerm plterm_47;
	PlTerm plterm_48[2];
	PlTerm plterm_49;
	PlTerm plterm_50;
	PlTerm plterm_51;
	/*****************************************************************/

	Pl_Start_Prolog(argc, argv);

	func = Pl_Find_Atom("prove");

	/*****************************************************************/
	not = Pl_Find_Atom("~");
	and = Pl_Find_Atom("and");
	or = Pl_Find_Atom("or");
	says = Pl_Find_Atom("says");
	implies = Pl_Find_Atom("->");
	colon = Pl_Find_Atom(":");
	geq = Pl_Find_Atom(">=");
	/*****************************************************************/

	Pl_Query_Begin(PL_TRUE);

	/*****************************************************************/
	plterm_12 = Pl_Mk_String("a_1");
	plterm_15 = Pl_Mk_String("suu_1");
	plterm_16 = Pl_Mk_String("wpu_1");
	plterm_14[0] = plterm_15;
	plterm_14[1] = plterm_16;
	plterm_13 = Pl_Mk_Compound(implies, 2, plterm_14);
	plterm_11[0] = plterm_12;
	plterm_11[1] = plterm_13;
	plterm_10 = Pl_Mk_Compound(says, 2, plterm_11);
	plterm_19 = Pl_Mk_String("a_2");
	plterm_20 = Pl_Mk_String("suu_1");
	plterm_18[0] = plterm_19;
	plterm_18[1] = plterm_20;
	plterm_17 = Pl_Mk_Compound(says, 2, plterm_18);
	plterm_9[0] = plterm_10;
	plterm_9[1] = plterm_17;
	plterm_8 = Pl_Mk_Compound(and, 2, plterm_9);
	plterm_27 = Pl_Mk_String("a_1");
	plterm_28 = Pl_Mk_String("a_2");
	plterm_26[0] = plterm_27;
	plterm_26[1] = plterm_28;
	plterm_25 = Pl_Mk_Compound(and, 2, plterm_26);
	plterm_29 = Pl_Mk_String("df_1");
	plterm_24[0] = plterm_25;
	plterm_24[1] = plterm_29;
	plterm_23 = Pl_Mk_Compound(says, 2, plterm_24);
	plterm_30 = Pl_Mk_String("df_1");
	plterm_22[0] = plterm_23;
	plterm_22[1] = plterm_30;
	plterm_21 = Pl_Mk_Compound(implies, 2, plterm_22);
	plterm_7[0] = plterm_8;
	plterm_7[1] = plterm_21;
	plterm_6 = Pl_Mk_Compound(and, 2, plterm_7);
	plterm_35 = Pl_Mk_String("a_1");
	plterm_36 = Pl_Mk_String("a_2");
	plterm_34[0] = plterm_35;
	plterm_34[1] = plterm_36;
	plterm_33 = Pl_Mk_Compound(and, 2, plterm_34);
	plterm_41 = Pl_Mk_String("wpu_1");
	plterm_44 = Pl_Mk_String("u_1");
	plterm_45 = Pl_Mk_String("df_1");
	plterm_43[0] = plterm_44;
	plterm_43[1] = plterm_45;
	plterm_42 = Pl_Mk_Compound(says, 2, plterm_43);
	plterm_40[0] = plterm_41;
	plterm_40[1] = plterm_42;
	plterm_39 = Pl_Mk_Compound(and, 2, plterm_40);
	plterm_46 = Pl_Mk_String("df_1");
	plterm_38[0] = plterm_39;
	plterm_38[1] = plterm_46;
	plterm_37 = Pl_Mk_Compound(implies, 2, plterm_38);
	plterm_32[0] = plterm_33;
	plterm_32[1] = plterm_37;
	plterm_31 = Pl_Mk_Compound(says, 2, plterm_32);
	plterm_5[0] = plterm_6;
	plterm_5[1] = plterm_31;
	plterm_4 = Pl_Mk_Compound(and, 2, plterm_5);
	plterm_49 = Pl_Mk_String("u_1");
	plterm_50 = Pl_Mk_String("df_1");
	plterm_48[0] = plterm_49;
	plterm_48[1] = plterm_50;
	plterm_47 = Pl_Mk_Compound(says, 2, plterm_48);
	plterm_3[0] = plterm_4;
	plterm_3[1] = plterm_47;
	plterm_2 = Pl_Mk_Compound(and, 2, plterm_3);
	plterm_51 = Pl_Mk_String("df_1");
	plterm_1[0] = plterm_2;
	plterm_1[1] = plterm_51;
	plterm_0 = Pl_Mk_Compound(implies, 2, plterm_1);
	arg[0] = plterm_0;
	/*****************************************************************/

	res = Pl_Query_Call(func, 1, arg);

	printf("Query:\n\t|- u : ((a_1 says (suu_1 -> wpu_1)) and (a_2 says suu_1) and (((a_1 and a_2) says df_1) -> df_1) and (a_1 and a_2 says ((wpu_1 and (u_1 says df_1)) -> df_1)) and (u_1 says df_1)) -> df_1\n%s.\n", res ? "true" : "false");

	Pl_Query_End(PL_RECOVER);

	Pl_Stop_Prolog();
	return 0;
}