Skip to content

Commit

Permalink
remove constraint of self-referencing edges
Browse files Browse the repository at this point in the history
  • Loading branch information
iTitus committed Jan 24, 2022
1 parent 15d7795 commit 5101d06
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public Edge<T> addEdge(Vertex<T> start, Vertex<T> end) {
}

public Edge<T> addEdge(Vertex<T> start, Vertex<T> end, BigRational weight) {
if (Objects.requireNonNull(start).equals(Objects.requireNonNull(end))) {
throw new IllegalArgumentException("start=end");
} else if (getEdgeByVertices(start, end).isPresent()) {
if (getEdgeByVertices(Objects.requireNonNull(start), Objects.requireNonNull(end)).isPresent()) {
throw new IllegalArgumentException("edge already exists");
} else if (!Objects.requireNonNull(weight).isPositive()) {
throw new IllegalArgumentException("weight");
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/io/github/ititus/commons/math/graph/Edge.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.ititus.commons.math.graph;

import io.github.ititus.commons.math.number.BigRational;
import io.github.ititus.commons.math.number.BigRationalConstants;

import java.util.Objects;

Expand All @@ -16,14 +15,12 @@ public final class Edge<T> {
private final BigRational weight;

Edge(Vertex<T> start, Vertex<T> end, BigRational weight) {
if (Objects.requireNonNull(start).equals(Objects.requireNonNull(end))) {
throw new IllegalArgumentException("start=end");
} else if (Objects.requireNonNull(weight).compareTo(BigRationalConstants.ZERO) <= 0) {
if (!Objects.requireNonNull(weight).isPositive()) {
throw new IllegalArgumentException("weight");
}

this.start = start;
this.end = end;
this.start = Objects.requireNonNull(start);
this.end = Objects.requireNonNull(end);
this.weight = weight;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/github/ititus/commons/math/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public Edge<T> addEdge(Vertex<T> start, Vertex<T> end) {
}

public Edge<T> addEdge(Vertex<T> start, Vertex<T> end, BigRational weight) {
if (Objects.requireNonNull(start).equals(Objects.requireNonNull(end))) {
throw new IllegalArgumentException("start=end");
} else if (getEdgeByVertices(start, end).isPresent()) {
if (getEdgeByVertices(Objects.requireNonNull(start), Objects.requireNonNull(end)).isPresent()) {
throw new IllegalArgumentException("edge already exists");
} else if (!Objects.requireNonNull(weight).isPositive()) {
throw new IllegalArgumentException("weight");
Expand Down

0 comments on commit 5101d06

Please sign in to comment.