Beispiel #1
0
int main()
{
	float target=60;
	float actual=0;
	float u=0;
	int ruleMatrix[7][7]={{NB,NB,NM,NM,NS,ZO,ZO},
	                      {NB,NB,NM,NS,NS,ZO,PS},
						  {NM,NM,NM,NS,ZO,PS,PS},
	                      {NM,NM,NS,ZO,PS,PM,PM},
	                      {NS,NS,ZO,PS,PS,PM,PM},
	                      {NS,ZO,PS,PM,PM,PM,PB},
	                      {ZO,ZO,PM,PM,PM,PB,PB}};
	float e_mf_paras[21]={-3,-3,-2,-3,-2,-1,-2,-1,0,-1,0,1,0,1,2,1,2,3,2,3,3};
	float de_mf_paras[21]={-3,-3,-2,-3,-2,-1,-2,-1,0,-1,0,1,0,1,2,1,2,3,2,3,3};
	float u_mf_paras[21]={-3,-3,-2,-3,-2,-1,-2,-1,0,-1,0,1,0,1,2,1,2,3,2,3,3};
    Fuzzy_controller fuzzy(100,65,50);
	fuzzy.setMf("trimf",e_mf_paras,"trimf",de_mf_paras,"trimf",u_mf_paras);
	fuzzy.setRule(ruleMatrix);
	cout<<"num   target    actual"<<endl;
	/*fuzzy.showInfo();*/
	for(int i=0;i<100;i++)
	{
		u=fuzzy.realize(target,actual);
		actual+=u;
		cout<<i<<"  "<<target<<"   "<<actual<<endl;
	}
	fuzzy.showInfo();
	system("pause");
	return 0;
}
Beispiel #2
0
void cl_fanny(int *nn,  /* = number of objects */
	      int *jpp, /* = number of variables for clustering */
	      int *kk,  /* = number of clusters */
	      double *x, double *dss, int *jdyss, double *valmd,
	      int *jtmd, int *ndyst, int *nsend, int *nelem,
	      int *negbr, double *syl, double *p, double *dp,
	      double *pt, int *nfuzz, double *esp, double *ef,
	      double *dvec, double *ttsyl,
	      double *obj, /* input/output;  see fuzzy() below */
	      int *ncluv, double *sylinf,
	      double *r, double *tol, int *maxit)
{
    int ktrue, trace_lev = (int) obj[1];
    Rboolean all_stats = (obj[0] == 0.);/* TODO: consider *not* doing caddy() */

    if (*jdyss != 1) { /* compute dissimilarities from data */
	int jhalt = 0;
	dysta3(nn, jpp, x, dss, ndyst, jtmd, valmd, &jhalt);
	if (jhalt) {
	    *jdyss = -1; return;
	}
    }

    fuzzy(*nn, *kk, p, dp, pt, dss, esp,
	  ef, obj, *r, *tol, maxit, trace_lev);

    caddy(*nn, *kk, p, /* -> */ &ktrue, nfuzz, ncluv, pt, trace_lev);

    obj[0] = (double) ktrue;

    /*	Compute "silhouette": */
    if (all_stats && 2 <= ktrue && ktrue < *nn) {
	int i, nhalf = *nn * (*nn - 1) / 2;
	double s = 0.; /* s := max( dss[i,j] ) */
	for(i = 0; i < nhalf; i++)
	    if (s < dss[i])
		s = dss[i];
	fygur(ktrue, *nn, ncluv, dss, s,
	      nsend, nelem, negbr, syl, dvec, pt, ttsyl, sylinf);
    }
    return;
} /* cl_fanny */
Beispiel #3
0
int main_loop(int client_socket, int motors_socket)
{
	char msg_buf[BUFSIZ];
	float phi, xleft, xright;
	int rc;

	while (1) {
		memset(msg_buf, 0, BUFSIZ);
		rc = recv(client_socket, msg_buf, BUFSIZ, 0);
		if (rc < 0) {
			fprintf(stderr, "recv returned exit status %d\n", errno);
			goto error;
		}
		if (rc == 0) {
			close(client_socket);
			break;
		}
		rc = parse_msg(msg_buf, &phi, &xleft, &xright);
		if (rc < 0) {
			fprintf(stderr, "parse_msg returned exit code %d\n", rc);
			continue;
		}
#if 0
		fuzzy(phi, xleft, xright);
#endif
		process_output(msg_buf, phi, xleft, xright);
		rc = send(motors_socket, msg_buf, strlen(msg_buf), 0);
		if (rc < 0) {
			fprintf(stderr, "send() returned exit status %d\n", errno);
			goto error;
		}
	}
	return 0;
error:
	return -errno;
}