001: /*
002: * <copyright>
003: *
004: * Copyright 2003-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.logistics.plugin.seanet;
027:
028: import java.util.Vector;
029: import java.util.Iterator;
030:
031: /**
032: A Node in the network. Nodes are connected by Link's.
033:
034: <p>The cost (distance) of the node is computed by its Network.
035:
036: **/
037:
038: public class Node extends LocationImpl {
039:
040: /** A number larger than any distance, used to initialize cost. **/
041: static final int HUGE = 100000;
042:
043: public Node(String name, double lat, double lon) {
044: super (lat, lon);
045: this .name = name;
046: }
047:
048: String name;
049:
050: public String getName() {
051: return this .name;
052: }
053:
054: Vector links = new Vector(3, 1);
055:
056: public Iterator getLinks() {
057: return links.iterator();
058: }
059:
060: /** Add Unidirectional Link from this to node to. **/
061: public void addLink(Node to, String name, int distance) {
062: links.add(new Link(name, distance, to));
063: }
064:
065: /** Minimum cost from From to here, so far. **/
066: int cost;
067:
068: public int getCost() {
069: return cost;
070: }
071:
072: public void setCost(int newValue) {
073: this .cost = newValue;
074: }
075:
076: public void propagateToLinks(Vector fringe2) {
077: int c1 = this .getCost();
078: for (Iterator i = this .getLinks(); i.hasNext();) {
079: Link link = ((Link) i.next());
080: if (link.isOpen()) {
081: int c2 = link.getToCost();
082: if (c1 + link.getDistance() < c2) {
083: link.setToCost(c1 + link.getDistance());
084: link.setToBack(this );
085: fringe2.add(link.getToNode());
086: }
087: }
088: }
089: }
090:
091: /** Next node along best path backward to From. **/
092: Node back;
093:
094: public Node getBack() {
095: return this .back;
096: }
097:
098: public void setBack(Node back) {
099: this .back = back;
100: }
101:
102: public String toString() {
103: return "node(\"" + name + "\"," + latitude + "," + longitude
104: + ")";
105: }
106:
107: }
|