Пример #1
0
int
main(int argc, char **argv)
{
    int ret;
    gid_t groups[NGROUPS];
    int ngroups;
    gid_t pag1, pag2;
    pid_t pid;

    if (argc != 1)
	errx(1, "Usage: %s", argv[0]);

    ngroups = getgroups(NGROUPS, groups);
    if (ngroups < 0)
	err(1, "getgroups %d", NGROUPS);
    pag1 = groups[1];
    pag2 = groups[2];
    printf("in parent ");
    print_groups(ngroups, groups);
    pid = fork();
    if (pid < 0)
	err(1, "fork");
    if (pid == 0) {
	ret = setpag();
	if (ret < 0)
	    err(1, "setpag");
	ngroups = getgroups(NGROUPS, groups);
	if (ngroups < 0)
	    err(1, "getgroups %d", NGROUPS);
	printf("in child ");
	print_groups(ngroups, groups);
	return 0;
    } else {
	int status;

	while (waitpid(pid, &status, WNOHANG | WUNTRACED) != pid);
	if (status)
	    return 1;
	ngroups = getgroups(NGROUPS, groups);
	if (ngroups < 0)
	    err(1, "getgroups %d", NGROUPS);
	printf("in parent ");
	print_groups(ngroups, groups);
	if (groups[1] == pag1 && groups[2] == pag2)
	    return 0;
	else
	    return 1;
    }
}
Пример #2
0
static void
print_tokinf (PLSA_TOKEN_INFORMATION_V2 ptok, size_t size,
	       PVOID got_start, PVOID gotinf_start, PVOID gotinf_end)
{
  if (fh == INVALID_HANDLE_VALUE)
    return;

  cyglsa_printf ("INCOMING: start: 0x%08x infstart: 0x%08x infend: 0x%08x\n",
	  (INT_PTR) got_start, (INT_PTR) gotinf_start,
	  (INT_PTR) gotinf_end);

  cyglsa_printf ("LSA_TOKEN_INFORMATION_V2: 0x%08x - 0x%08x\n",
	  (INT_PTR) ptok, (INT_PTR) ptok + size);

  /* User SID */
  cyglsa_printf ("User: (attr: 0x%lx)", ptok->User.User.Attributes);
  print_sid (" ", -1, (PISID) ptok->User.User.Sid);

  /* Groups */
  print_groups (ptok->Groups);

  /* Primary Group SID */
  print_sid ("Primary Group: ", -1, (PISID)ptok->PrimaryGroup.PrimaryGroup);

  /* Privileges */
  print_privs (ptok->Privileges);

  /* Owner */
  print_sid ("Owner: ", -1, (PISID) ptok->Owner.Owner);

  /* Default DACL */
  print_dacl (ptok->DefaultDacl.DefaultDacl);

  // CloseHandle (fh);
}
Пример #3
0
void print_groups(struct gp* groups) {
    struct wd *words = NULL;

    if (groups == NULL) {
        return;
    }

    words = groups->words;
    while (words) {
        printf("%s ", words->word);
        words = words->next;
    }
    printf("\n");

    print_groups(groups->left);
    print_groups(groups->right);
}
Пример #4
0
static void ULOG_print(const void *ip, const struct xt_entry_target *target,
                       int numeric)
{
	const struct ipt_ulog_info *loginfo
	    = (const struct ipt_ulog_info *) target->data;

	printf("ULOG ");
	printf("copy_range %u nlgroup ", (unsigned int)loginfo->copy_range);
	print_groups(loginfo->nl_group);
	if (strcmp(loginfo->prefix, "") != 0)
		printf("prefix `%s' ", loginfo->prefix);
	printf("queue_threshold %u ", (unsigned int)loginfo->qthreshold);
}
Пример #5
0
int main(int argc, char *argv[]) {
    char var[VARLEN];
    int maxlen = VARLEN;
    int first_n = 0;
    struct gp* groups = NULL;
    
    /* get parameter */
    if ((first_n = get_para(argc, argv)) < 0) {
        printf ("%s: input group flag n.\n", argv[0]);
        return -1;
    }

    while (readvar(var, maxlen) > 0) {
        add_to_groups(groups, var, first_n);
    }

    print_groups(groups);
    return 0;
}
Пример #6
0
/* Saves the union ipt_targinfo in parsable form to stdout. */
static void save(const struct ipt_ip *ip,
		 const struct ipt_entry_target *target)
{
	const struct ipt_ulog_info *loginfo
	    = (const struct ipt_ulog_info *) target->data;

	if (strcmp(loginfo->prefix, "") != 0)
		printf("--ulog-prefix \"%s\" ", loginfo->prefix);

	if (loginfo->nl_group != ULOG_DEFAULT_NLGROUP) {
		printf("--ulog-nlgroup ");
		print_groups(loginfo->nl_group);
	}
	if (loginfo->copy_range)
		printf("--ulog-cprange %d ", (int)loginfo->copy_range);

	if (loginfo->qthreshold != ULOG_DEFAULT_QTHRESHOLD)
		printf("--ulog-qthreshold %d ", (int)loginfo->qthreshold);
}
Пример #7
0
static void ULOG_save(const void *ip, const struct xt_entry_target *target)
{
	const struct ipt_ulog_info *loginfo
	    = (const struct ipt_ulog_info *) target->data;

	if (strcmp(loginfo->prefix, "") != 0) {
		fputs("--ulog-prefix ", stdout);
		xtables_save_string(loginfo->prefix);
	}

	if (loginfo->nl_group != ULOG_DEFAULT_NLGROUP) {
		printf("--ulog-nlgroup ");
		print_groups(loginfo->nl_group);
	}
	if (loginfo->copy_range)
		printf("--ulog-cprange %u ", (unsigned int)loginfo->copy_range);

	if (loginfo->qthreshold != ULOG_DEFAULT_QTHRESHOLD)
		printf("--ulog-qthreshold %u ", (unsigned int)loginfo->qthreshold);
}
Пример #8
0
int main(int argc, char **argv) {
    verbose = true;
    FILE *cfgfile = fopen(argv[1], "r");
    if(!cfgfile) {
        printf("Error: could not open config file.\n");
        return 1;
    }
    fscanf(cfgfile, "%d", &objc);
    if(objc <= 0) {
        printf("Error: objc <= 0.\n");
        fclose(cfgfile);
        return 1;
    }
    // reading labels
    int classc;
    int labels[objc];
    fscanf(cfgfile, "%d", &classc);
    size_t i;
    for(i = 0; i < objc; ++i) {
        fscanf(cfgfile, "%d", &labels[i]);
    }
    // reading labels end
    fscanf(cfgfile, "%d", &dmatrixc);
    if(dmatrixc <= 0) {
        printf("Error: dmatrixc <= 0.\n");
        fclose(cfgfile);
        return 1;
    }
    char filenames[dmatrixc][BUFF_SIZE];
    size_t j;
    for(j = 0; j < dmatrixc; ++j) {
        fscanf(cfgfile, "%s", filenames[j]);
    }
    char outfilename[BUFF_SIZE];
    fscanf(cfgfile, "%s", outfilename);
    fscanf(cfgfile, "%d", &clustc);
    if(clustc <= 0) {
        printf("Error: clustc <= 0.\n");
        fclose(cfgfile);
        return 1;
    }
    int insts;
    fscanf(cfgfile, "%d", &insts);
    if(insts <= 0) {
        printf("Error: insts <= 0.\n");
        fclose(cfgfile);
        return 1;
    }
    fscanf(cfgfile, "%d", &max_iter);
    if(insts <= 0) {
        printf("Error: max_iter <= 0.\n");
        fclose(cfgfile);
        return 1;
    }
    fscanf(cfgfile, "%lf", &epsilon);
    if(dlt(epsilon, 0.0)) {
        printf("Error: epsilon < 0.\n");
        fclose(cfgfile);
        return 1;
    }
    fscanf(cfgfile, "%lf", &mfuz);
    if(dlt(mfuz, 1.0)) {
        printf("Error: mfuz < 1.0.\n");
        fclose(cfgfile);
        return 1;
    }
    fscanf(cfgfile, "%lf", &qexp);
    if(dlt(qexp, 1.0)) {
        printf("Error: qexp < 1.0.\n");
        fclose(cfgfile);
        return 1;
    }
    fclose(cfgfile);
    freopen(outfilename, "w", stdout);
    printf("###Configuration summary:###\n");
    printf("Number of objects: %d\n", objc);
    printf("Number of clusters: %d\n", clustc);
    printf("Number of instances: %d\n", insts);
    printf("Maximum interations: %d\n", max_iter);
    printf("Parameter m: %lf\n", mfuz);
    printf("Parameter q: %lf\n", qexp);
    printf("############################\n");
    st_matrix best_memb;
    st_matrix best_dists;
    st_matrix best_weights;
    // memory allocation start
    dmatrix = malloc(sizeof(st_matrix) * dmatrixc);
    for(j = 0; j < dmatrixc; ++j) {
        init_st_matrix(&dmatrix[j], objc, objc);
    }
    init_st_matrix(&memb, objc, clustc);
    init_st_matrix(&best_memb, objc, clustc);
    size_t k;
    membvec = malloc(sizeof(st_matrix) * clustc);
    global_dmatrix = malloc(sizeof(st_matrix) * clustc);
    for(k = 0; k < clustc; ++k) {
        init_st_matrix(&membvec[k], objc, 1);
        init_st_matrix(&global_dmatrix[k], objc, objc);
    }
    init_st_matrix(&dists, clustc, objc);
    init_st_matrix(&best_dists, clustc, objc);
    init_st_matrix(&weights, clustc, dmatrixc);
    init_st_matrix(&best_weights, clustc, dmatrixc);
    // memory allocation end
    for(j = 0; j < dmatrixc; ++j) {
        if(!load_data(filenames[j], &dmatrix[j])) {
            printf("Error: could not load matrix file.\n");
            goto END;
        }
    }
    mfuzval = 1.0 / (mfuz - 1.0);
    qexpval = 1.0 / (qexp - 1.0);
    double avg_partcoef;
    double avg_modpcoef;
    double avg_partent;
    double avg_aid;
    st_matrix dists_t;
    init_st_matrix(&dists_t, dists.ncol, dists.nrow);
    st_matrix agg_dmatrix;
    init_st_matrix(&agg_dmatrix, objc, objc);
    silhouet *csil;
    silhouet *fsil;
    silhouet *ssil;
    silhouet *avg_csil;
    silhouet *avg_fsil;
    silhouet *avg_ssil;
    int *pred;
    st_matrix *groups;
    srand(time(NULL));
    size_t best_inst;
    double best_inst_adeq;
    double cur_inst_adeq;
    for(i = 1; i <= insts; ++i) {
        printf("Instance %d:\n", i);
        cur_inst_adeq = run();
        pred = defuz(&memb);
        groups = asgroups(pred, objc, classc);
        transpose_(&dists_t, &dists);
        aggregate_dmatrices(&agg_dmatrix, &weights);
        csil = crispsil(groups, &agg_dmatrix);
        fsil = fuzzysil(csil, groups, &memb, mfuz);
        ssil = simplesil(pred, &dists_t);
        if(i == 1) {
            avg_partcoef = partcoef(&memb);
            avg_modpcoef = modpcoef(&memb);
            avg_partent = partent(&memb);
            avg_aid = avg_intra_dist(&memb, &dists_t, mfuz);
            avg_csil = csil;
            avg_fsil = fsil;
            avg_ssil = ssil;
        } else {
            avg_partcoef = (avg_partcoef + partcoef(&memb)) / 2.0;
            avg_modpcoef = (avg_modpcoef + modpcoef(&memb)) / 2.0;
            avg_partent = (avg_partent + partent(&memb)) / 2.0;
            avg_aid = (avg_aid +
                        avg_intra_dist(&memb, &dists_t, mfuz)) / 2.0;
            avg_silhouet(avg_csil, csil);
            avg_silhouet(avg_fsil, fsil);
            avg_silhouet(avg_ssil, ssil);
            free_silhouet(csil);
            free(csil);
            free_silhouet(fsil);
            free(fsil);
            free_silhouet(ssil);
            free(ssil);
        }
        free(pred);
        free_st_matrix(groups);
        free(groups);
        if(i == 1 || cur_inst_adeq < best_inst_adeq) {
            mtxcpy(&best_memb, &memb);
            mtxcpy(&best_dists, &dists);
            mtxcpy(&best_weights, &weights);
            best_inst_adeq = cur_inst_adeq;
            best_inst = i;
        }
    }
	printf("\n");
    printf("Best adequacy %.15lf on instance %d.\n", best_inst_adeq,
            best_inst);
    printf("\n");
    print_memb(&best_memb);
    print_weights(&best_weights);

    pred = defuz(&best_memb);
    groups = asgroups(pred, objc, classc);
    print_header("Partitions", HEADER_SIZE);
    print_groups(groups);

    print_header("Average indexes", HEADER_SIZE);
    printf("\nPartition coefficient: %.10lf\n", avg_partcoef);
    printf("Modified partition coefficient: %.10lf\n", avg_modpcoef);
    printf("Partition entropy: %.10lf (max: %.10lf)\n", avg_partent,
            log(clustc));
    printf("Average intra cluster distance: %.10lf\n", avg_aid);

    transpose_(&dists_t, &best_dists);
    print_header("Best instance indexes", HEADER_SIZE);
    printf("\nPartition coefficient: %.10lf\n", partcoef(&best_memb));
    printf("Modified partition coefficient: %.10lf\n",
            modpcoef(&best_memb));
    printf("Partition entropy: %.10lf (max: %.10lf)\n",
            partent(&best_memb), log(clustc));
    printf("Average intra cluster distance: %.10lf\n",
            avg_intra_dist(&best_memb, &dists_t, mfuz));

    print_header("Averaged crisp silhouette", HEADER_SIZE);
    print_silhouet(avg_csil);
    print_header("Averaged fuzzy silhouette", HEADER_SIZE);
    print_silhouet(avg_fsil);
    print_header("Averaged simple silhouette", HEADER_SIZE);
    print_silhouet(avg_ssil);

    aggregate_dmatrices(&agg_dmatrix, &best_weights);
    csil = crispsil(groups, &agg_dmatrix);
    print_header("Best instance crisp silhouette", HEADER_SIZE);
    print_silhouet(csil);
    fsil = fuzzysil(csil, groups, &best_memb, mfuz);
    print_header("Best instance fuzzy silhouette", HEADER_SIZE);
    print_silhouet(fsil);
    ssil = simplesil(pred, &dists_t);
    print_header("Best instance simple silhouette", HEADER_SIZE);
    print_silhouet(ssil);

    free_silhouet(avg_csil);
    free(avg_csil);
    free_silhouet(avg_fsil);
    free(avg_fsil);
    free_silhouet(avg_ssil);
    free(avg_ssil);
    free_silhouet(csil);
    free(csil);
    free_silhouet(fsil);
    free(fsil);
    free_silhouet(ssil);
    free(ssil);
    free(pred);
    free_st_matrix(groups);
    free(groups);
    free_st_matrix(&dists_t);
    free_st_matrix(&agg_dmatrix);
END:
    fclose(stdout);
    for(j = 0; j < dmatrixc; ++j) {
        free_st_matrix(&dmatrix[j]);
    }
    free(dmatrix);
    free_st_matrix(&memb);
    free_st_matrix(&best_memb);
    for(k = 0; k < clustc; ++k) {
        free_st_matrix(&membvec[k]);
        free_st_matrix(&global_dmatrix[k]);
    }
    free(membvec);
    free(global_dmatrix);
    free_st_matrix(&dists);
    free_st_matrix(&best_dists);
    free_st_matrix(&weights);
    free_st_matrix(&best_weights);
    return 0;
}
Пример #9
0
int
main (int argc, char *argv[])
{
	FILE *kb;
	
	struct GModule *module;
	struct
	{
		struct Option *file;
		struct Option *log;
	}
	parm;
	struct
	{
		struct Flag *all;
	}
	flag;

	/* setup some basic GIS stuff */
	G_gisinit (argv[0]);	
	module = G_define_module ();
	module->description = "Displays structured contents of a Dempster-Shafer knowledge base";
	
	/* do not pause after a warning message was displayed */
	G_sleep_on_error (0);

	/* Parameters */
	parm.file = G_define_option ();
	parm.file->key = "file";
	parm.file->type = TYPE_STRING;
	parm.file->required = YES;
	parm.file->description = "Name of the knowledge base file to display";

	parm.log = G_define_option ();
	parm.log->key = "output";
	parm.log->type = TYPE_STRING;
	parm.log->required = NO;
	parm.log->description = "File to write contents to (default: display on screen)";
	
	/* Flags */
	flag.all = G_define_flag ();
	flag.all->key='a';
	flag.all->description = "Show all hypotheses (including type AUTO)";
	
	/* parse command line */
	if (G_parser (argc, argv))
	{
		exit (-1);
	}

	/* check if we have read/write access to knowledge base */
	errno = 0;
	kb = fopen (parm.file->answer, "r");
	if ( kb == NULL ) {
		G_fatal_error ("Cannot open knowledge base file for reading.\nReason: %s.", strerror (errno));
	} else {
		fclose(kb);
	}
	
	open_xml_file ( parm.file->answer );
	
	if ( parm.log->answer != NULL ) {
		errno = 0;
		lp = fopen (parm.log->answer,"w+");
		if ( lp == NULL ) {
			G_fatal_error ("Cannot create output file for writing.\nReason: %s.", strerror (errno));
		}
	} else {	
		/* send output to terminal */
		lp = stdout;
	}
	
	/* now output information */
	print_header ( parm.file->answer );
	print_hypotheses ( flag.all->answer );
	print_const_evidence ();
	print_rast_evidence ();
	print_vect_evidence ();
	print_groups ();

	exit (EXIT_SUCCESS);
}
Пример #10
0
int main (int argc, char **argv)
{
	long sys_ngroups;

#ifdef HAVE_GETGROUPS
	int ngroups;
	GETGROUPS_T *groups;
	int pri_grp;
	int i;
	struct group *gr;
#else
	char *logname;
	char *getlogin ();
#endif

	sys_ngroups = sysconf (_SC_NGROUPS_MAX);
#ifdef HAVE_GETGROUPS
	groups = malloc (sys_ngroups * sizeof (GETGROUPS_T));
#endif
	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	if (argc == 1) {

		/*
		 * Called with no arguments - give the group set for the
		 * current user.
		 */

#ifdef HAVE_GETGROUPS
		/*
		 * This system supports concurrent group sets, so I can ask
		 * the system to tell me which groups are currently set for
		 * this process.
		 */

		ngroups = getgroups (sys_ngroups, groups);
		if (ngroups < 0) {
			perror ("getgroups");
			exit (1);
		}

		/*
		 * The groupset includes the primary group as well.
		 */

		pri_grp = getegid ();
		for (i = 0; i < ngroups; i++)
			if (pri_grp == (int) groups[i])
				break;

		if (i != ngroups)
			pri_grp = -1;

		/*
		 * Print out the name of every group in the current group
		 * set. Unknown groups are printed as their decimal group ID
		 * values.
		 */

		if (pri_grp != -1) {
			if ((gr = getgrgid (pri_grp)))
				printf ("%s", gr->gr_name);
			else
				printf ("%d", pri_grp);
		}

		for (i = 0; i < ngroups; i++) {
			if (i || pri_grp != -1)
				putchar (' ');

			if ((gr = getgrgid (groups[i])))
				printf ("%s", gr->gr_name);
			else
				printf ("%ld", (long) groups[i]);
		}
		putchar ('\n');
#else
		/*
		 * This system does not have the getgroups() system call, so
		 * I must check the groups file directly.
		 */

		if ((logname = getlogin ()))
			print_groups (logname);
		else
			exit (1);
#endif
	} else {

		/*
		 * The invoker wanted to know about some other user. Use
		 * that name to look up the groups instead.
		 */

		print_groups (argv[1]);
	}
	exit (0);
}
Пример #11
0
int main(int argc, char **argv) {
	verbose = false;
	int insts;
    // Opening and reading config file.
    FILE *cfgfile = fopen(argv[1], "r");
    if(!cfgfile) {
        printf("Error: could not open config file.\n");
        return 1;
    }
    fscanf(cfgfile, "%d", &objc);
    if(objc <= 0) {
        printf("Error: objc <= 0.\n");
        return 2;
    }
    int labels[objc];
    // reading labels
    int classc;
    fscanf(cfgfile, "%d", &classc);
	size_t i;
    for(i = 0; i < objc; ++i) {
        fscanf(cfgfile, "%d", &labels[i]);
    }
    // reading labels end
    fscanf(cfgfile, "%d", &dmatrixc);
    if(dmatrixc <= 0) {
        printf("Error: dmatrixc <= 0.\n");
        return 2;
    }
    char dmtx_file_name[dmatrixc][BUFF_SIZE];
	size_t j;
    for(j = 0; j < dmatrixc; ++j) {
        fscanf(cfgfile, "%s", dmtx_file_name[j]);
    }
    char out_file_name[BUFF_SIZE];
    fscanf(cfgfile, "%s", out_file_name);
    fscanf(cfgfile, "%d", &clustc);
    if(clustc <= 0) {
        printf("Error: clustc <= 0.\n");
        return 2;
    }
    fscanf(cfgfile, "%d", &medoids_card);
    if(medoids_card <= 0) {
        printf("Error: medoids_card <= 0.\n");
        return 2;
    }
    fscanf(cfgfile, "%d", &insts);
    if(insts <= 0) {
        printf("Error: insts <= 0.\n");
        return 2;
    }
    fscanf(cfgfile, "%lf", &theta);
    if(dlt(theta, 0.0)) {
        printf("Error: theta < 0.\n");
        return 2;
    }
    fscanf(cfgfile, "%d", &max_iter);
    fscanf(cfgfile, "%lf", &epsilon);
    if(dlt(epsilon, 0.0)) {
        printf("Error: epsilon < 0.\n");
        return 2;
    }
    fscanf(cfgfile, "%lf", &mfuz);
    if(!dgt(mfuz, 0.0)) {
        printf("Error: mfuz <= 0.\n");
        return 2;
    }
    fclose(cfgfile);
    // Done reading config file.
    freopen(out_file_name, "w", stdout);
	mfuzval = 1.0 / (mfuz - 1.0);
    printf("######Config summary:######\n");
    printf("Number of clusters: %d.\n", clustc);
    printf("Medoids cardinality: %d.\n", medoids_card);
    printf("Number of iterations: %d.\n", max_iter);
    printf("Epsilon: %.15lf.\n", epsilon);
    printf("Theta: %.15lf.\n", theta);
    printf("Parameter m: %.15lf.\n", mfuz);
    printf("Number of instances: %d.\n", insts);
    printf("###########################\n");
	size_t k;
	// Allocating memory start
	parc_cluster_adeq = malloc(sizeof(double) * clustc);
    parc_obj_adeq = malloc(sizeof(double) * objc);
	dmatrix = malloc(sizeof(double **) * dmatrixc);
	for(j = 0; j < dmatrixc; ++j) {
		dmatrix[j] = malloc(sizeof(double *) * objc);
		for(i = 0; i < objc; ++i) {
			dmatrix[j][i] = malloc(sizeof(double) * objc);
		}
	}
	medoids = malloc(sizeof(size_t **) * clustc);
	size_t ***best_medoids = malloc(sizeof(size_t **) * clustc);
	for(k = 0; k < clustc; ++k) {
		medoids[k] = malloc(sizeof(size_t *) * dmatrixc);
		best_medoids[k] = malloc(sizeof(size_t *) * dmatrixc);
        for(j = 0; j < dmatrixc; ++j) {
            medoids[k][j] = malloc(sizeof(size_t) * medoids_card);
            best_medoids[k][j] = malloc(sizeof(size_t) * medoids_card);
        }
	}
	weights = malloc(sizeof(double *) * clustc);
	double **best_weights = malloc(sizeof(double *) * clustc);
	for(k = 0; k < clustc; ++k) {
		weights[k] = malloc(sizeof(double) * dmatrixc);
		best_weights[k] = malloc(sizeof(double) * dmatrixc);
	}
	memb = malloc(sizeof(double *) * objc);
	double **best_memb = malloc(sizeof(double *) * objc);
	for(i = 0; i < objc; ++i) {
		memb[i] = malloc(sizeof(double) * clustc);
		best_memb[i] = malloc(sizeof(double) * clustc);
	}
	// Allocating memory end
	for(j = 0; j < dmatrixc; ++j) {
		if(!load_data(dmtx_file_name[j], dmatrix[j], objc, objc)) {
			printf("Error: could not load %s.\n", dmtx_file_name[j]);
			goto END;
		}
	}
    size_t best_inst;
    double best_inst_adeq;
    double cur_inst_adeq;
	srand(time(NULL)); // Random seed.
    // Start main program loop.
	for(i = 1; i <= insts; ++i) {
		printf("Instance %u:\n", i);
		cur_inst_adeq = run();
        if(i == 1 || cur_inst_adeq < best_inst_adeq) {
            // Saves the best configuration based on the adequacy.
            mtxcpy_d(best_memb, memb, objc, clustc);
            mtxcpy_d(best_weights, weights, clustc, dmatrixc);
            for(k = 0; k < clustc; ++k) {
                mtxcpy_size_t(best_medoids[k], medoids[k], dmatrixc,
                        medoids_card);
            }
            best_inst_adeq = cur_inst_adeq;
            best_inst = i;
        }
	}
    // Print the best configuration, confusion matrix and the CR
    // index.
	printf("\n");
    printf("Best adequacy %.15lf on instance %d.\n",
            best_inst_adeq, best_inst);
    printf("\n");
    print_medoids(best_medoids);
    printf("\n");
	print_memb(best_memb);
	printf("\n");
	print_weights(best_weights);
	printf("\n");
    global_energy();
    printf("\n");
    int *pred = defuz(memb, objc, clustc);
    print_groups(pred, objc, clustc);
    double **confmtx = confusion(pred, labels, objc);
    printf("\nConfusion matrix (class x predicted):\n");
    print_mtx_d(confmtx, classc, classc, 0);
    ++classc;
    for(i = 0; i < classc; ++i) {
        free(confmtx[i]);
    }
    free(confmtx);
    printf("Corrected Rand: %.7lf\n", corand(pred, labels, objc));
    free(pred);
    // Freeing memory.
END:
    fclose(stdout);
	for(i = 0; i < dmatrixc; ++i) {
		for(j = 0; j < objc; ++j) {
			free(dmatrix[i][j]);
		}
		free(dmatrix[i]);
	}
	free(dmatrix);
	for(k = 0; k < clustc; ++k) {
        for(j = 0; j < dmatrixc; ++j) {
            free(medoids[k][j]);
            free(best_medoids[k][j]);
        }
		free(medoids[k]);
		free(best_medoids[k]);
		free(weights[k]);
		free(best_weights[k]);
	}
	free(medoids);
	free(best_medoids);
	free(weights);
	free(best_weights);
	for(i = 0; i < objc; ++i) {
		free(memb[i]);
		free(best_memb[i]);
	}
	free(memb);
	free(best_memb);
	free(parc_cluster_adeq);
    free(parc_obj_adeq);
	return 0;
}
Пример #12
0
/* move track, then manipulate title string */
int netmd_put_track_in_group(usb_dev_handle* dev, minidisc *md, int track, int group)
{
	int i = 0;
	int j = 0;
	int found = 0;

	printf("netmd_put_track_in_group(dev, %i, %i)\nGroup Count %i\n", track, group, md->group_count);

	if(group >= md->group_count)
	{
		return 0;
	}

	print_groups(md);

	/* remove track from old group */
	for(i = 0; i < md->group_count; i++)
	{
		if(i == 0)
		{
			/* if track is before first real group */
			if(md->groups[i+1].start == 0)
			{
				/* nothing in group  */
				found = 1;
			}
			if((track + 1) < md->groups[i+1].start)
			{
				found = 1;
				for(j = i+1; j < md->group_count; j++)
				{
					md->groups[j].start--;
					if(md->groups[j].finish != 0)
						md->groups[j].finish--;
				}
			}
		}
		else if(md->groups[i].start <= (track + 1) && md->groups[i].finish >= (track + 1))
		{
			found = 1;
			/* decrement start/finish for all following groups */
			for(j = i+1; j < md->group_count; j++)
			{
				md->groups[j].start--;
				if(md->groups[j].finish != 0)
					md->groups[j].finish--;
			}	
		}
	}

	/* if track is in between groups */
	if(!found)
	{
		for(i = 2; i < md->group_count; i++)
		{
			if(md->groups[i].start >= (track+1) && md->groups[i-1].finish <= (track+1))
			{
				found = 1;
				/* decrement start/finish for all groups including and after this one */
				for(j = i; j < md->group_count; j++)
				{
					md->groups[j].start--;
					if(md->groups[j].finish != 0)
						md->groups[j].finish--;
				}	
			}
		}
	}

	print_groups(md);

	/* insert track into group range */
	if(md->groups[group].finish != 0)
	{
		md->groups[group].finish++;
	}
	else
	{
		if(md->groups[group].start == 0)
			md->groups[group].start = track + 1;
		else
			md->groups[group].finish = md->groups[group].start + 1;
	}
	
	/* if not last group */
	if((group + 1) < md->group_count)
	{
		int j = 0;
		for(j = group + 1; j < md->group_count; j++)
		{
			/* if group is NOT empty */
			if(md->groups[j].start != 0 || md->groups[j].finish != 0)
			{
				md->groups[j].start++;
				if(md->groups[j].finish != 0)
				{	
					md->groups[j].finish++;
				}
			}
		}
	}

	/* what does it look like now? */
	print_groups(md);

	if(md->groups[group].finish != 0)
	{
	   	netmd_move_track(dev, track, md->groups[group].finish - 1);
	}
	else
	{
		if(md->groups[group].start != 0)
			netmd_move_track(dev, track, md->groups[group].start - 1);
		else
			netmd_move_track(dev, track, md->groups[group].start);
	}
	
	return netmd_write_disc_header(dev, md);
}
Пример #13
0
int
main(int argc, char **argv)
{
    int cc;
    int numGroups = 0;
    int enumGrp = 0;
    char **groups=NULL;
    char **groupPoint;
    struct groupInfoEnt *grpInfo = NULL;
    int options = GRP_ALL;
    int all;
    int slots;

    if (lsb_init(argv[0]) < 0) {
	lsb_perror("lsb_init");
	return -1;
    }

    slots = 0;
    while ((cc = getopt(argc, argv, "Vhs")) != EOF) {
        switch (cc) {
	    case 'r':
		options |= GRP_RECURSIVE;
		break;
	    case 'V':
		fputs(_LS_VERSION_, stderr);
		return -1;
		break;
	    case 's':
		++slots;
		break;
	    case 'h':
	    default:
		usage(argv[0]);
	    return -1;
        }
    }

    if (slots) {
	if (strstr(argv[0], "bugroup")) {
	    fprintf(stderr, "bugroup: -s option applies only to bmgroup\n");
	    return -1;
	}
    }

    numGroups = getNames(argc, argv, optind, &groups, &all, "group");
    enumGrp = numGroups;

    if (numGroups) {
        options &= ~GRP_ALL;
        groupPoint = groups;
    } else
        groupPoint = NULL;

    if (strstr(argv[0], "bugroup") != NULL) {
        options |= USER_GRP;
        grpInfo = lsb_usergrpinfo(groupPoint, &enumGrp, options);
    } else if (strstr(argv[0], "bmgroup") != NULL) {
	options |= HOST_GRP;
        grpInfo = lsb_hostgrpinfo(groupPoint, &enumGrp, options);
    }

    if (grpInfo == NULL) {
        if (lsberrno == LSBE_NO_USER_GROUP || lsberrno == LSBE_NO_HOST_GROUP ) {
            if (options & HOST_GRP)
                lsb_perror("host group");
            else
                lsb_perror("user group");
	    FREEUP(groups);
            return -1;
        }
        if (lsberrno == LSBE_BAD_GROUP && groups)

            lsb_perror (groups[enumGrp]);
        else
	    lsb_perror(NULL);
        FREEUP (groups);
	return -1;
    }

    if (numGroups != enumGrp && numGroups != 0 && lsberrno == LSBE_BAD_GROUP) {
	if (groups)
            lsb_perror (groups[enumGrp]);
        else
            lsb_perror(NULL);
        FREEUP(groups);
	return -1;
    }

    FREEUP(groups);
    if (slots == 0)
	prtGroups(grpInfo, enumGrp, options);
    else
	print_groups(grpInfo, enumGrp);

    return 0;
}