/** * <p>Adds a new node to the network. Nodes are associated to all layers.</p> * * @param xCoord Node position in x-axis * @param yCoord Node position in y-axis * @param name Node name ({@code null} will be converted to "Node " + node identifier) * @param attributes SortedMap for user-defined attributes ({@code null} means 'no attribute'). Each key represents the attribute name, whereas value represents the attribute value * @return The newly created node object * @see com.net2plan.interfaces.networkDesign.Node */ public Node addNode(double xCoord, double yCoord, String name, Map<String, String> attributes) { return addNode(null, xCoord, yCoord, name, attributes); }
/** Creates an empty design with no nodes, links etc. * @return see above */ public static WNet createEmptyDesign () { final NetPlan np = new NetPlan (); np.getNetworkLayerDefault().setName("WDM"); np.addLayer("IP", "IP Layer", "", "", null, null); np.addNode(0, 0, WNetConstants.WNODE_NAMEOFANYCASTORIGINNODE , null); np.addNode(0, 0, WNetConstants.WNODE_NAMEOFANYCASTDESTINATION, null); final WNet res = new WNet (np); return res; }
public static void main(String[] args) throws Exception { final NetPlan np = new NetPlan (); final Node n1 = np.addNode(0 , 0 , "name1" , null); final Node n2 = np.addNode(0 , 0 , "name2" , null); final Node n3 = np.addNode(0 , 0 , "name3" , null); final Link e12 = np.addLink(n1,n2,3,100,200000,null); final Link e23 = np.addLink(n2,n3,3,100,200000,null); final Resource r1 = np.addResource("CPU" , "nameRes1" , Optional.of(n1) , 10 , "Mbps" , null , 5 , null); final Resource r2 = np.addResource("RAM" , "nameRes2" , Optional.of(n2) , 10 , "Mbps" , null , 5 , null); final Demand d = np.addDemand(n1 , n3 , 0 , RoutingType.SOURCE_ROUTING , null); d.setServiceChainSequenceOfTraversedResourceTypes(Arrays.asList("CPU" , "RAM")); final Route r = np.addServiceChain(d , 2.0 , Arrays.asList(1.0,2.0,3.0,4.0) , Arrays.asList(r1,e12,r2,e23) , null); final NetworkLayer layer = np.getNetworkLayerDefault(); layer.setName("WDM"); JFrame frame = new JFrame("Example"); frame.getContentPane().setLayout(new FlowLayout()); frame.setPreferredSize(new Dimension (600,600)); //frame.add(new FigureLinkSequencePanel(r.getPath() , layer , r.getSeqOccupiedCapacitiesIfNotFailing() , "Route " + r.getIndex() , r.getCarriedTraffic())); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
netPlan.addNode(0 , 2 , "Node 0" , null); netPlan.addNode(5 , 1 , "Node 1" , null); netPlan.addNode(5 , 0 , "Node 2" , null); netPlan.addNode(1 , 0 , "Node 3" , null); netPlan.addNode(2 , 1 , "Node 4" , null); netPlan.addNode(3 , 2 , "Node 5" , null); netPlan.addNode(4 , 2 , "Node 6" , null); netPlan.addNode(5 , 3 , "Node 7" , null); netPlan.addNode(3 , 0 , "Node 8" , null); netPlan.addNode(3 , 1 , "Node 9" , null); netPlan.addNode(4 , 1 , "Node 10" , null); netPlan.addNode(1 , 3 , "Node 11" , null); netPlan.addNode(4 , 0 , "Node 12" , null);
double yCoord = Double.parseDouble(data[2]); String name = data[0]; Node node = netPlan.addNode(xCoord, yCoord, name, null); String asId = data[5]; String type = data[6];
double yCoord = Double.parseDouble(data[2]); String name = data[0]; long nodeId = netPlan.addNode(xCoord, yCoord, name, null).getId (); nodeName2Id.put(name, nodeId);
public List<AjtRcMenu> getNonBasicRightClickMenusInfo() { final NetPlan np = callback.getDesign(); final List<AjtRcMenu> res = new ArrayList<> (); res.add(new AjtRcMenu("Add node", e->np.addNode (0 , 0 , "Node " + np.getNumberOfNodes() , null), (a,b)->true, null)); res.add(new AjtRcMenu("Remove selected nodes", e->getSelectedElements().forEach(dd->((Node)dd).remove()) , (a,b)->b>0, null)); res.add(new AjtRcMenu("Show selected nodes", e->getSelectedElements().forEach(ee->callback.getVisualizationState().showOnCanvas(ee)) , (a,b)->b>0, null)); res.add(new AjtRcMenu("Hide selected nodes", e->getSelectedElements().forEach(ee->callback.getVisualizationState().hideOnCanvas(ee)) , (a,b)->b>0, null)); res.add(new AjtRcMenu("Switch selected nodes' coordinates from (x,y) to (y,x)", e->getSelectedElements().forEach(node->node.setXYPositionMap(new Point2D.Double(node.getXYPositionMap().getY(), node.getXYPositionMap().getX()))) , (a,b)->b>0, null)); res.add(new AjtRcMenu("Create planning domain restricted to selected nodes", e->np.restrictDesign(getSelectedElements()) , (a,b)->b>0, null)); return res; } }
while (true) { try { planningDomains.add(getString ("planningDomain_" + (planningDomains.size()))); } catch(Exception e) { break; } } Node newNode = netPlan.addNode(nodeId , xCoord, yCoord, nodeName, null); newNode.setDescription(getStringOrDefault ("description" , ""));
@Override public void addNode(Point2D pos) { final Node node = callback.getDesign().addNode(pos.getX(), pos.getY(), "Node" + callback.getDesign().getNumberOfNodes(), null); callback.getVisualizationState().recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(); callback.addNetPlanChange(); callback.getPickManager().pickElements(node); callback.updateVisualizationAfterPick(); }
nodeAttributes.put("wc", ((Element) node.getElementsByTagName("wc").item(0)).getAttribute("number")); final Node n = templateNetPlan.addNode(xCoord, yCoord, name, nodeAttributes); n.setPopulation(Double.parseDouble(node.getAttribute("nodePopulation")));
if (endElementName.equals("node")) netPlan.addNode(xCoord, yCoord, nodeName, attributeMap); return;
/** Adds a node to the design * @param xCoord the x coordinate * @param yCoord the y coordinate * @param name the node name, that should be unique * @param type the type of node: a user-defined string * @return see above */ public WNode addNode (double xCoord, double yCoord, String name , String type) { if (name == null) ex("Names cannot be null"); if (name.contains(WNetConstants.LISTSEPARATORANDINVALIDNAMECHARACTER)) throw new Net2PlanException("Names cannot contain the character: " + WNetConstants.LISTSEPARATORANDINVALIDNAMECHARACTER); if (getNodes().stream().anyMatch(n->n.getName().equals(name))) ex("Names cannot be repeated"); final WNode n = new WNode (getNetPlan().addNode(xCoord, yCoord, name, null)); n.setType(type); addIpLink(getAnycastOriginNode(), n, Double.MAX_VALUE, false); addIpLink(n , getAnycastDestinationNode(), Double.MAX_VALUE, false); return n; }
private void parseNode(NetPlan netPlan) throws XMLStreamException { final long nodeId = getLong ("id"); if (nodeId >= netPlan.nextElementId.toLong()) throw new Net2PlanException ("A network element has an id higher than the nextElementId"); final double xCoord = getDouble ("xCoord"); final double yCoord = getDouble ("yCoord"); final String nodeName = getString ("name"); double population = 0; try { population = getDouble ("population"); } catch (Exception e) {} String siteName = null; try { siteName = getString ("siteName"); } catch (Exception e) {} boolean isUp = true; try { isUp = getBoolean ("isUp"); } catch (Exception e) {} final Set<String> planningDomains = new HashSet<> (); while (true) { try { planningDomains.add(getString ("planningDomain_" + (planningDomains.size()))); } catch(Exception e) { break; } } Node newNode = netPlan.addNode(nodeId , xCoord, yCoord, nodeName, null); for (String pd : planningDomains) newNode.addToPlanningDomain(pd); newNode.setFailureState(isUp); newNode.setPopulation(population); if (siteName != null) newNode.setSiteName(siteName); /* read the icons information and put it in a map for later (layers are not created yet!) */ for (long layerId : getListLong("layersWithIconsDefined")) { List<Pair<Node,URL>> iconsThisLayerSoFar = nodeAndLayerToIconURLMap.get (layerId); if (iconsThisLayerSoFar == null) { iconsThisLayerSoFar = new LinkedList<> (); nodeAndLayerToIconURLMap.put(layerId , iconsThisLayerSoFar); } URL url = null; try { url = new URL (getString ("nodeIconURLLayer_" + layerId)); } catch (Exception e) {} iconsThisLayerSoFar.add(Pair.of(newNode , url)); } readAndAddAttributesToEndAndPdForNodes(newNode, "node"); }
for (String columnName : columnNames) att.put(ATTRIBUTEPREFIX + columnName , readField(row , columnName)); Node newNode = netPlan.addNode(xCoord , yCoord , name , att); mapNo2Node.put(no , newNode); for (String columnName : columnNames) att.put(ATTRIBUTEPREFIX + columnName , readField(row , columnName)); Node newNode = netPlan.addNode(xCoord , yCoord , name , att); mapNoOfZone2Node.put(no , newNode);
double yCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "yCoord")); String nodeName = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "name")); Node newNode = netPlan.addNode(xCoord, yCoord, nodeName, null); mapOldId2Node.put (nodeId , newNode);
@Override public void addNode(Point2D pos) { final double scale = canvas.getCurrentCanvasScale(); final Point2D swingPoint = new Point2D.Double(pos.getX() * scale, -pos.getY() * scale); final GeoPosition geoPosition = OSMController.OSMMapUtils.convertPointToGeo(swingPoint); if (!OSMController.OSMMapUtils.isInsideBounds(geoPosition.getLongitude(), geoPosition.getLatitude())) { throw new OSMException("The node is out of the map's bounds", "Problem while adding node"); } final NetPlan netPlan = callback.getDesign(); final Node node = netPlan.addNode(geoPosition.getLongitude(), geoPosition.getLatitude(), "Node" + netPlan.getNumberOfNodes(), null); callback.getVisualizationState().recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(); mapController.refreshTopologyAlignment(); callback.addNetPlanChange(); callback.getPickManager().pickElements(node); callback.updateVisualizationAfterPick(); }
boolean isUp = true; try { isUp = xmlStreamReader.getAttributeAsBoolean(xmlStreamReader.getAttributeIndex(null, "isUp")); } catch (Exception e) {} Node newNode = netPlan.addNode(xCoord, yCoord, nodeName, null); newNode.setFailureState(isUp); mapOldId2Node.put (nodeId , newNode);
for (int cont = 0; cont < num_o ; cont ++) final Node n = netPlan.addNode(0, cont, "Origin-" + cont, null); setNodeType (n , LOCATIONTYPE.CANDIDATELOCATION_PLANT); setFixedSettingCost(n, 100.0); final Node n = netPlan.addNode(5, cont, "DistributionCenter-" + cont, null); setNodeType (n , LOCATIONTYPE.CANDIDATELOCATION_DISTRIBUTIONCENTER); setFixedSettingCost(n, 100.0); final Node n = netPlan.addNode(10, cont, "Destination-" + cont, null); setNodeType (n , LOCATIONTYPE.DESTINATION); setPenalizationPerUndeliveredUnit(n, 100.0);
for (int n = 0; n < numNodes; n++) netPlan.addNode(0, 0, null, null); } else { netPlan = new NetPlan((File) cli.getParsedOptionValue("input-file"));
if (e == null) e = this.addNode(0, 0, "", null); nodesThis_otherNotThis.add(e);