Esempio n. 1
0
func main() {
	var filename string
	// Get filename
	fmt.Println("Enter file to be read")
	fmt.Scanf("%s\n", &filename)
	fmt.Println()
	// Read in file to slice
	aRelation := file.IntLines(filename)
	printRel(aRelation)
	// Test for Reflexivity
	reflexive := isReflexive(aRelation)
	if reflexive {
		fmt.Println("The relation is reflexive\n")
	}
	// Test for Symmetry
	symmetric := isSymmetric(aRelation)
	if symmetric {
		fmt.Println("The relation is symmetric\n")
	}
	// Test for Transitivity
	transitive := isTransitive(aRelation)
	if transitive {
		fmt.Println("The relation is transitive\n")
	}
	// Output Results
	if reflexive && symmetric && transitive {
		fmt.Println("The relation is an equivalence relation.\n")
		fmt.Println("The equivalence classes are:")
		eClasses(aRelation)
	} else {
		fmt.Println("The relation is not an equivalence relation.")
	}
}
Esempio n. 2
0
// open and read a file containing graph information in the form of
// two integers per line, the first being the tail of an edge and the
// second being the head of that edge.
// Load the requested information into a graph data structure and return
// a pointer to it
// !!!
func loadgraph() *graph {

	fileInts := file.IntLines(fileToken)
	size := fileInts[0][0]
	fileInts = fileInts[1:]
	V := fillVertices(size * 2)
	E := fillEdges(size * 2)
	for i, v := range fileInts {
		if pos(v[0]) {
			if pos(v[1]) {
				E[i].tail = V[v[0]+size-1]
				E[i].head = V[v[1]-1]
				V[v[0]+size-1].edges = append(V[v[0]+size-1].edges, E[i])
				V[v[1]-1].edges = append(V[v[1]-1].edges, E[i])
				E[i+size].tail = V[v[1]+size-1]
				E[i+size].head = V[v[0]-1]
				V[v[1]+size-1].edges = append(V[v[1]+size-1].edges, E[i+size])
				V[v[0]-1].edges = append(V[v[0]-1].edges, E[i+size])
			} else {
				E[i].tail = V[v[0]+size-1]
				E[i].head = V[abs(v[1])+size-1]
				V[v[0]+size-1].edges = append(V[v[0]+size-1].edges, E[i])
				V[abs(v[1])+size-1].edges = append(V[abs(v[1])+size-1].edges, E[i])
				E[i+size].tail = V[abs(v[1])-1]
				E[i+size].head = V[v[0]-1]
				V[abs(v[1])-1].edges = append(V[abs(v[1])-1].edges, E[i+size])
				V[v[0]-1].edges = append(V[v[0]-1].edges, E[i+size])
			}
		} else {
			if pos(v[1]) {
				E[i].tail = V[abs(v[0])-1]
				E[i].head = V[v[1]-1]
				V[abs(v[0])-1].edges = append(V[abs(v[0])-1].edges, E[i])
				V[v[1]-1].edges = append(V[v[1]-1].edges, E[i])
				E[i+size].tail = V[v[1]+size-1]
				E[i+size].head = V[abs(v[0])+size-1]
				V[v[1]+size-1].edges = append(V[v[1]+size-1].edges, E[i+size])
				V[abs(v[0])+size-1].edges = append(V[abs(v[0])+size-1].edges, E[i+size])
			} else {
				E[i].tail = V[abs(v[0])-1]
				E[i].head = V[abs(v[1])+size-1]
				V[abs(v[0])-1].edges = append(V[abs(v[0])-1].edges, E[i])
				V[abs(v[1])+size-1].edges = append(V[abs(v[1])+size-1].edges, E[i])
				E[i+size].tail = V[abs(v[1])-1]
				E[i+size].head = V[abs(v[0])+size-1]
				V[abs(v[1])-1].edges = append(V[abs(v[1])-1].edges, E[i+size])
				V[abs(v[0])+size-1].edges = append(V[abs(v[0])+size-1].edges, E[i+size])
			}
		}
	}
	G := new(graph)
	G.vertices = V
	G.edges = E
	return G
}