<commit_before>/*******************************************************************************
 * Copyright (c) 2017 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the 2-clause BSD License 
 * which accompanies this distribution, and is available at
 * https://opensource.org/licenses/BSD-2-Clause
 *
 * Contributors:
 *     <NAME> and others - initial API and implementation
 *******************************************************************************/


package com.net2plan.research.metrohaul.networkModel;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;

import com.google.common.collect.Sets;
import com.net2plan.interfaces.networkDesign.Demand;
import com.net2plan.interfaces.networkDesign.Link;
import com.net2plan.interfaces.networkDesign.Net2PlanException;
import com.net2plan.interfaces.networkDesign.NetPlan;
import com.net2plan.interfaces.networkDesign.NetworkElement;
import com.net2plan.interfaces.networkDesign.Node;
import com.net2plan.interfaces.networkDesign.Resource;
import com.net2plan.libraries.GraphUtils;
import com.net2plan.utils.Constants.RoutingType;
import com.net2plan.utils.Pair;
import com.net2plan.utils.StringUtils;

import cern.colt.matrix.tdouble.DoubleFactory1D;
import cern.colt.matrix.tdouble.DoubleMatrix1D;

/** This class represents an IP over WDM network with potential VNF placement. This is the main model class, that gives access 
 * to the key methods to play with the network
 *
 */
public class WNet extends WAbstractNetworkElement
{
	private static final String ATTNAME_VNFTYPELIST = "VnfTypeListMatrix";
	private static final String ATTNAME_USERSERVICELIST = "userServiceListMatrix";

	public WNet (NetPlan np)
	{
		super (np);
		this.np = np;
		if(np.getNumberOfNodes() < 2 || np.getNumberOfLayers() != 2) throw new Net2PlanException("Incorrect number of nodes or layers");
	}
	private final NetPlan np;

	@Override
	public NetPlan getNe() { return (NetPlan) e;  }

	/** Returns the object identifying the WDM layer
	 * @return see above
	 */
	public WLayerWdm getWdmLayer () { return new WLayerWdm(np.getNetworkLayer(0)); }
	/** Returns the object identifying the IP layer
	 * @return see above
	 */
	public WLayerIp getIpLayer () { return new WLayerIp(np.getNetworkLayer(1)); }
	
	/** Returns the list of network nodes, in increasing order according to its id
	 * @return see above
	 */
	public List<WNode> getNodes () { return np.getNodes().stream().map(n->new WNode(n)).filter(n->!n.isVirtualNode()).collect(Collectors.toCollection(ArrayList::new));  }
	/** Returns the list of fibers, in increasing order according to its id
	 * @return see above
	 */
	public List<WFiber> getFibers () { return np.getLinks(getWdmLayer().getNe()).stream().map(n->new WFiber(n)).collect(Collectors.toCollection(ArrayList::new));  }
	/** Returns the list of lightpath requests, in increasing order according to its id
	 * @return see above
	 */
	public List<WLightpathRequest> getLightpathRequests () { return np.getDemands(getWdmLayer().getNe()).stream().map(n->new WLightpathRequest(n)).collect(Collectors.toCollection(ArrayList::new));  }
	/** Returns the list of lightpaths, in increasing order according to its id
	 * @return see above
	 */
	public List<WLightpathUnregenerated> getLightpaths () { return np.getRoutes(getWdmLayer().getNe()).stream().map(n->new WLightpathUnregenerated(n)).collect(Collectors.toCollection(ArrayList::new));  }

	/** Returns the list of IP links, in increasing order according to its id
	 * @return see above
	 */
	public List<WIpLink> getIpLinks () { return np.getLinks(getIpLayer().getNe()).stream().map(n->new WIpLink(n)).filter(e->!e.isVirtualLink()).collect(Collectors.toCollection(ArrayList::new));  }

	/** Returns the list of service chain requests, in increasing order according to its id
	 * @return see above
	 */
	public List<WServiceChainRequest> getServiceChainRequests () { return np.getDemands(getIpLayer().getNe()).stream().map(n->new WServiceChainRequest(n)).collect(Collectors.toCollection(ArrayList::new));  }

	/** Returns the list of service chains, in increasing order according to its id
	 * @return see above
	 */
	public List<WServiceChain> getServiceChains () { return np.getRoutes(getIpLayer().getNe()).stream().map(n->new WServiceChain(n)).collect(Collectors.toCollection(ArrayList::new));  }
	
	/** Saves this network in the given file
	 * @param f see above
	 */
	public void saveToFile (File f) { getNetPlan().saveToFile(f); }

	/** Creates an empty design with no nodes, links etc.
	 * @return see above
	 */
	public static WNet createEmptyDesign ()
	{
		final NetPlan np = new NetPlan ();
		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);<commit_msg>Small fix (renaming default layer to WDM in WNet constructor)<commit_after>/*******************************************************************************
 * Copyright (c) 2017 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the 2-clause BSD License 
 * which accompanies this distribution, and is available at
 * https://opensource.org/licenses/BSD-2-Clause
 *
 * Contributors:
 *     <NAME> and others - initial API and implementation
 *******************************************************************************/


package com.net2plan.research.metrohaul.networkModel;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;

import com.google.common.collect.Sets;
import com.net2plan.interfaces.networkDesign.Demand;
import com.net2plan.interfaces.networkDesign.Link;
import com.net2plan.interfaces.networkDesign.Net2PlanException;
import com.net2plan.interfaces.networkDesign.NetPlan;
import com.net2plan.interfaces.networkDesign.NetworkElement;
import com.net2plan.interfaces.networkDesign.Node;
import com.net2plan.interfaces.networkDesign.Resource;
import com.net2plan.libraries.GraphUtils;
import com.net2plan.utils.Constants.RoutingType;
import com.net2plan.utils.Pair;
import com.net2plan.utils.StringUtils;

import cern.colt.matrix.tdouble.DoubleFactory1D;
import cern.colt.matrix.tdouble.DoubleMatrix1D;

/** This class represents an IP over WDM network with potential VNF placement. This is the main model class, that gives access 
 * to the key methods to play with the network
 *
 */
public class WNet extends WAbstractNetworkElement
{
	private static final String ATTNAME_VNFTYPELIST = "VnfTypeListMatrix";
	private static final String ATTNAME_USERSERVICELIST = "userServiceListMatrix";

	public WNet (NetPlan np)
	{
		super (np);
		this.np = np;
		if(np.getNumberOfNodes() < 2 || np.getNumberOfLayers() != 2) throw new Net2PlanException("Incorrect number of nodes or layers");
	}
	private final NetPlan np;

	@Override
	public NetPlan getNe() { return (NetPlan) e;  }

	/** Returns the object identifying the WDM layer
	 * @return see above
	 */
	public WLayerWdm getWdmLayer () { return new WLayerWdm(np.getNetworkLayer(0)); }
	/** Returns the object identifying the IP layer
	 * @return see above
	 */
	public WLayerIp getIpLayer () { return new WLayerIp(np.getNetworkLayer(1)); }
	
	/** Returns the list of network nodes, in increasing order according to its id
	 * @return see above
	 */
	public List<WNode> getNodes () { return np.getNodes().stream().map(n->new WNode(n)).filter(n->!n.isVirtualNode()).collect(Collectors.toCollection(ArrayList::new));  }
	/** Returns the list of fibers, in increasing order according to its id
	 * @return see above
	 */
	public List<WFiber> getFibers () { return np.getLinks(getWdmLayer().getNe()).stream().map(n->new WFiber(n)).collect(Collectors.toCollection(ArrayList::new));  }
	/** Returns the list of lightpath requests, in increasing order according to its id
	 * @return see above
	 */
	public List<WLightpathRequest> getLightpathRequests () { return np.getDemands(getWdmLayer().getNe()).stream().map(n->new WLightpathRequest(n)).collect(Collectors.toCollection(ArrayList::new));  }
	/** Returns the list of lightpaths, in increasing order according to its id
	 * @return see above
	 */
	public List<WLightpathUnregenerated> getLightpaths () { return np.getRoutes(getWdmLayer().getNe()).stream().map(n->new WLightpathUnregenerated(n)).collect(Collectors.toCollection(ArrayList::new));  }

	/** Returns the list of IP links, in increasing order according to its id
	 * @return see above
	 */
	public List<WIpLink> getIpLinks () { return np.getLinks(getIpLayer().getNe()).stream().map(n->new WIpLink(n)).filter(e->!e.isVirtualLink()).collect(Collectors.toCollection(ArrayList::new));  }

	/** Returns the list of service chain requests, in increasing order according to its id
	 * @return see above
	 */
	public List<WServiceChainRequest> getServiceChainRequests () { return np.getDemands(getIpLayer().getNe()).stream().map(n->new WServiceChainRequest(n)).collect(Collectors.toCollection(ArrayList::new));  }

	/** Returns the list of service chains, in increasing order according to its id
	 * @return see above
	 */
	public List<WServiceChain> getServiceChains () { return np.getRoutes(getIpLayer().getNe()).stream().map(n->new WServiceChain(n)).collect(Collectors.toCollection(ArrayList::new));  }
	
	/** Saves this network in the given file
	 * @param f see above
	 */
	public void saveToFile (File f) { getNetPlan().saveToFile(f); }

	/** 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);
{'fraction_non_alphanumeric': 0.14523632303684406, 'fraction_numerical': 0.005582433941198363, 'mean_word_length': 5.2457873329459614, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2374203', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3146, 'n_words': 865}