Skip to content

GitLab

  • Menu
    • Projects Groups Snippets
      Help
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • P project06
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1
    • Issues 1
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • cs2-23wi
  • project06
  • Merge requests
  • !1

Merged
Created 2 years ago by Winter Pearson@winterMaintainer

Updates

  • Overview 0
  • Commits 4
  • Pipelines 2
  • Changes 4
  • James C Bowden @jbowden added 1 commit 2 years ago

    added 1 commit

    • 291e3cd9 - Update NodeGraph.java

    Compare with previous version

  • James C Bowden @jbowden merged 2 years ago

    merged

  • James C Bowden @jbowden mentioned in commit ec5e6ead 2 years ago

    mentioned in commit ec5e6ead

  • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply
Compare
  • version 1
    4deaed8c
    2 years ago

  • master (base)

and
  • latest version
    291e3cd9
    4 commits, 2 years ago

  • version 1
    4deaed8c
    3 commits, 2 years ago

4 files
+ 119
- 8413

    Preferences

    File browser
    Compare changes

Some changes are not shown

For a faster browsing experience, some files are collapsed by default.

da‎ta‎
queen14_‎14.graph‎ +0 -8374
src/edu/caltec‎h/cs2/coloring‎
NodeGra‎ph.java‎ +96 -35
tests/edu/‎caltech/cs2‎
datastr‎uctures‎
MinFourHea‎pTests.java‎ +22 -3
proj‎ect06‎
DSaturTe‎sts.java‎ +1 -1
data/queen14_14.graph deleted 100644 → 0
+ 0
- 8374
  • View file @ 78532aa7

Files with large changes are collapsed by default.

src/edu/caltech/cs2/coloring/NodeGraph.java
+ 96
- 35
  • View file @ 291e3cd9

  • Edit in single-file editor

  • Edit in Web IDE


Show all unchanged lines Show 20 lines
public class NodeGraph {
private final Node[] nodes;
/**
* Represents one node in the graph
*/
private static class Node {
public int name;
public int color;
public ISet<Node> neighbors;
public ISet<Integer> neighborColors;
public ISet<Integer> neighborsColored;
public ISet<Node> neighbors; // The set of this node's neighboring nodes
public ISet<Integer> neighborColors; // The colors which its neighbors use
public ISet<Integer> neighborsUncolored; // The names of its neighbors which aren't yet colored
public Node(int name, int color) {
this.name = name;
this.color = color;
this.neighbors = new ChainingHashSet<>();
this.neighborColors = new ChainingHashSet<>();
this.neighborsColored = new ChainingHashSet<>();
this.neighborsUncolored = new ChainingHashSet<>();
}
public void addNeighbor(Node neighbor) {
this.neighbors.add(neighbor);
this.neighborsUncolored.add(neighbor.name);
}
@Override
Show 20 lines Show all unchanged lines Show 20 lines
return this.name;
}
}
private final Node[] nodes;
/**
* Creates a new graph
* @param n The (fixed) number of vertices for the graph to have. They will be
* "named" with the numbers 0 through n.
*/
public NodeGraph(int n) {
this.nodes = new Node[n];
for (int i = 0; i < n; i++) {
Show 20 lines Show all unchanged lines Show 20 lines
}
}
public int numberOfVertices() {
return this.nodes.length;
}
/**
* Whether or not a vertex is colored yet
* @param n The name of the vertex
* @return True if the vertex has a color, false if it doesn't yet
*/
public boolean isColored(int n) {
return this.nodes[n].color != 0;
}
/**
* Gets the color of a given vertex
* @param n The name of the vertex
* @return The vertex's color, or 0 if it doesn't have one yet
*/
public int getColor(int n) {
return this.nodes[n].color;
}
/**
* Sets the color of a vertex
* @param n The name of the vertex to set the color of
* @param color The color to set it to
*/
public void setColor(int n, int color) {
if (this.isColored(n)) {
throw new IllegalArgumentException("" + n + " already has a color.");
throw new IllegalArgumentException(n + " already has a color.");
}
if (color <= 0) {
throw new IllegalArgumentException("only numbers >= 1 are valid colors");
throw new IllegalArgumentException("Only numbers >= 1 are valid colors, not " + color);
}
checkColoringIsValid(n, color);
this.nodes[n].color = color;
for (Node m : this.nodes[n].neighbors) {
m.neighborColors.add(color);
m.neighborsColored.add(n);
m.neighborsUncolored.remove(n);
}
}
private void checkColoringIsValid(int n, int color) {
ISet<Integer> adjs = this.neighbors(n);
for (int v : adjs) {
if (this.nodes[v].color == color) {
throw new IllegalColoringException();
}
/**
* Gets a vertex's neighbors
* @param n The name of the vertex
* @return A list of the names of that vertex's neighbors
*/
public ISet<Integer> neighbors(int n) {
ISet<Integer> adj = new ChainingHashSet<>();
ISet<Node> neighbors = this.nodes[n].neighbors;
for (Node neigh : neighbors) {
adj.add(neigh.name);
}
return adj;
}
public void addEdge(int n, int m) {
this.nodes[n].neighbors.add(this.nodes[m]);
this.nodes[m].neighbors.add(this.nodes[n]);
}
/**
* Gets the degree of saturation of a given vertex
* (i.e., the number of unique colors across its neighbors)
* @param n The name of the vertex
* @return Its degree of saturation
*/
public int degreeOfSaturation(int n) {
return this.nodes[n].neighborColors.size();
}
public int numNeighbors(int n) {
return this.nodes[n].neighbors.size() - this.nodes[n].neighborsColored.size();
/**
* Gets the number of uncolored neighbors of a given vertex
* @param n The name of the vertex
* @return How many of its neighbors don't yet have colors
*/
public int numUncoloredNeighbors(int n) {
return this.nodes[n].neighborsUncolored.size();
}
/**
* Gets the (fixed) number of vertices in the graph
* @return The total number of vertices
*/
public int numVertices() {
return this.nodes.length;
}
public ISet<Integer> neighbors(int n) {
ISet<Integer> adj = new ChainingHashSet<>();
ISet<Node> neighbors = this.nodes[n].neighbors;
for (Node neigh : neighbors) {
adj.add(neigh.name);
}
return adj;
/**
* Adds an edge between two vertices
* @param n The name of one vertex
* @param m The name of the other vertex
*/
public void addEdge(int n, int m) {
this.nodes[n].addNeighbor(this.nodes[m]);
this.nodes[m].addNeighbor(this.nodes[n]);
}
/**
* Gets the current coloring of the graph
* @return A map between each vertex's name and its color
*/
public IDictionary<Integer, Integer> getColoring() {
IDictionary<Integer, Integer> coloring = new ChainingHashDictionary<>(MoveToFrontDictionary::new);
for (Node n : this.nodes) {
Show 20 lines Show all unchanged lines Show 20 lines
return coloring;
}
/**
* Checks if a vertex can validly be colored with a given color
* @param n The name of the vertex
* @param color The color for it to have
* @throws IllegalColoringException If this would cause an illegal coloring
*/
private void checkColoringIsValid(int n, int color) {
ISet<Integer> adjs = this.neighbors(n);
for (int v : adjs) {
if (this.nodes[v].color == color) {
throw new IllegalColoringException();
}
}
}
@Override
public String toString() {
StringBuilder result = new StringBuilder("{");
Show 20 lines Show all unchanged lines Show 20 lines
}
return result + "}";
}
}
\ No newline at end of file
}
tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
+ 22
- 3
  • View file @ 291e3cd9

  • Edit in single-file editor

  • Edit in Web IDE


Show all unchanged lines Show 20 lines
@Tag("C")
@Order(3)
@DisplayName("Attempting to modify the priority of a nonexistent element throws an exception")
@TestDescription("This test checks that if an element doesn't exist in the heap, you're implementation " +
@TestDescription("This test checks that if an element doesn't exist in the heap, your implementation " +
"should not be able to call increaseKey and decreaseKey on such element.")
@TestHint("Make sure you are throwing an exception for nonexistent elements in increaseKey and decreaseKey")
@DependsOn({"increaseKey", "decreaseKey"})
Show 20 lines Show all unchanged lines Show 20 lines
});
}
@Test
@Tag("C")
@Order(3)
@DisplayName("Calling increaseKey with a lower priority or decreaseKey with a higher priority throws an exception")
@TestDescription("This test checks that increaseKey and decreaseKey only accept the arguments they should.")
@TestHint("Make sure you are throwing an exception when increaseKey is asked to decrease a key's priority, " +
"and vice versa for decreaseKey.")
@DependsOn({"increaseKey", "decreaseKey"})
public void testChangeKeyWrongWay() {
MinFourHeap<Integer> heap = new MinFourHeap<>();
heap.enqueue(new IPriorityQueue.PQElement<>(10, 10));
assertThrows(IllegalArgumentException.class, () -> {
heap.increaseKey(new IPriorityQueue.PQElement<>(10, 9));
});
assertThrows(IllegalArgumentException.class, () -> {
heap.decreaseKey(new IPriorityQueue.PQElement<>(10, 11));
});
}
@Test
@Tag("C")
@Order(4)
Show 20 lines Show all unchanged lines Show 20 lines
@TestHint("Make sure that all these methods exist (i.e. you have written a percolateDown (or equiv. name) method and findSmallestChild method) and that you are accounting for:\n" +
"1. Cases where some or all of the children are null and/or out of bounds\n" +
"2. Cases where all children have a higher priority than their parent, so no swapping should occur")
@DependsOn({"enqueue", "size", "increaseKey", "decreaseKey", "data (field)"})
@DependsOn({"enqueue", "size", "dequeue", "increaseKey", "decreaseKey", "data (field)"})
@CsvSource({"100, 30000, 15000", "42, 10000, 5000"})
public void stressTestIncreaseDecrease(int seed, int size, int numToReplace) {
MinFourHeap<Integer> heap = new MinFourHeap<>();
Show 20 lines Show all unchanged lines Show 20 lines
@TestHint("Make sure that all these methods exist (i.e. you have written a percolateDown (or equiv. name) method and findSmallestChild method) and that you are accounting for:\n" +
"1. Cases where some or all of the children are null and/or out of bounds\n" +
"2. Cases where all children have a higher priority than their parent, so no swapping should occur")
@DependsOn({"enqueue", "dequeue", "size", "data (field)"})
@DependsOn({"enqueue", "dequeue", "size", "data (field)", "keyToIndexMap (field)"})
public void stressTestEnqueueDequeue(int seed, int size) {
MinFourHeap<Integer> heap = new MinFourHeap<>();
Comparator<Integer> c = new IntegerComparator();
Show 20 lines Show all unchanged lines
tests/edu/caltech/cs2/project06/DSaturTests.java
+ 1
- 1
  • View file @ 291e3cd9

  • Edit in single-file editor

  • Edit in Web IDE


Show all unchanged lines Show 20 lines
"mulsol.i.5.graph", "myciel2.graph", "myciel3.graph",
"myciel4.graph", "myciel5.graph", "myciel6.graph",
"myciel7.graph", "queen10_10.graph", "queen11_11.graph",
"queen12_12.graph", "queen13_13.graph", "queen14_14.graph",
"queen12_12.graph", "queen13_13.graph",
"queen15_15.graph", "queen16_16.graph", "queen5_5.graph",
"queen6_6.graph", "queen7_7.graph", "queen8_12.graph",
"queen8_8.graph", "queen9_9.graph", "school1.graph",
Show 20 lines Show all unchanged lines
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Lock merge request
Unlocked
2
2 participants
James C Bowden
Winter Pearson
Reference: cs2-23wi/project06!1
Source branch: updates

Menu

Projects Groups Snippets
Help