当前位置: 首页>>代码示例>>Java>>正文


Java Transformer.transform方法代码示例

本文整理汇总了Java中org.apache.commons.collections15.Transformer.transform方法的典型用法代码示例。如果您正苦于以下问题:Java Transformer.transform方法的具体用法?Java Transformer.transform怎么用?Java Transformer.transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.collections15.Transformer的用法示例。


在下文中一共展示了Transformer.transform方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculate

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/**
 * Calculates the top event for the values given by the functionTransformer.
 * 
 * @param transformer
 *            the transformer from the variables to the values
 * @return the top event
 */
public double calculate(Transformer<T, Double> transformer) {

	for (Entry<T, Var> entry : variables.entrySet()) {
		T t = entry.getKey();
		Var var = entry.getValue();
		double value = transformer.transform(t);
		var.setValue(value);
	}

	for (VarNode node : nodes) {

		double r = node.getVar().getValue();

		double low = node.getLo().getValue();
		double high = node.getHi().getValue();

		// Shannon decomposition
		double y = r * high + (1 - r) * low;
		node.setValue(y);
	}

	return root.getValue();
}
 
开发者ID:felixreimann,项目名称:jreliability,代码行数:31,代码来源:BDDTopEvent.java

示例2: buildAuxiliaryNodeDisjointGraph

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/** Builds an auxiliary graph for the application of edge-disjoint shortest-path pair algorithms to node-disjoint problems.
 * 
 * @param graph Graph representing the network
 * @param nev Object responsible for returning weights for edges
 * @param originNode Origin node
 * @param destinationNode Destination node
 * @return Auxiliary graph, and its corresponding object returning edge weights */
public static Pair<Graph<Node, Link>, Transformer<Link, Double>> buildAuxiliaryNodeDisjointGraph(final Graph<Node, Link> graph, final Transformer<Link, Double> nev, Node originNode, Node destinationNode)
{
	final Graph<Node, Link> auxGraph = buildAuxiliaryNodeDisjointGraph(graph, originNode, destinationNode);

	Transformer<Link, Double> auxNev = new Transformer<Link, Double>()
	{
		@Override
		public Double transform(Link edge)
		{
			if (graph.containsEdge(edge))
			{
				if (edge.getId() < 0) throw new RuntimeException("Bad");
				return nev.transform(edge);
			} else if (auxGraph.containsEdge(edge)) { return 1.0; }

			throw new RuntimeException("Bad");
		}
	};

	return Pair.of(auxGraph, auxNev);
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:29,代码来源:GraphUtils.java

示例3: filterGraph

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/** <p>Filters a graph removing those edges whose weight is equal to {@code Double.MAX_VALUE}, or whose capacity is below a certain threshold.</p>
 * 
 * <p><b>Important</b>: Returned graph is not backed in the input one, so changes will not be reflected on it.
 * 
 * @param <V> Class type for vertices
 * @param <E> Class type for edges
 * @param graph Graph representing the network
 * @param nev Object responsible for returning weights for edges
 * @param edgeSpareCapacityTransformer Object responsible for returning capacity for edges (if null, it will not applied)
 * @param requiredCapacity Capacity threshold. Edges whose capacity is below that value it will be removed
 * @return Filtered graph */
public static <V, E> Graph<V, E> filterGraph(Graph<V, E> graph, final Transformer<E, Double> nev, final Transformer<E, Double> edgeSpareCapacityTransformer, final double requiredCapacity)
{
	EdgePredicateFilter<V, E> linkFilter = new EdgePredicateFilter<V, E>(new Predicate<E>()
	{
		@Override
		public boolean evaluate(E edge)
		{
			if (nev != null && nev.transform(edge) == Double.MAX_VALUE)
				return false;
			else if (edgeSpareCapacityTransformer != null && edgeSpareCapacityTransformer.transform(edge) < requiredCapacity) return false;

			return true;
		}
	});

	return linkFilter.transform(graph);
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:29,代码来源:GraphUtils.java

示例4: lengthTransformation

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/** This method does the following length transformation:
 * 
 * <pre> c'(v,w) = c(v,w) - d (s,w) + d (s,v) </pre>
 * 
 * @param graph1 the graph
 * @param slTrans The shortest length transformer
 * @return the transformed graph
 * @since 0.3.0 */
private Transformer<E, Double> lengthTransformation(Graph<V, E> graph1, Transformer<V, Number> slTrans)
{
	Map<E, Double> map = new LinkedHashMap<E, Double>();

	for (E link : graph1.getEdges())
	{
		double newWeight;

		if (slTrans.transform(graph1.getSource(link)) == null)
		{
			newWeight = Double.MAX_VALUE;
		} else
		{
			newWeight = nev.transform(link) - slTrans.transform(graph1.getDest(link)).doubleValue() + slTrans.transform(graph1.getSource(link)).doubleValue();
			if (newWeight < 0 || newWeight > -1e-6) newWeight = 0; /* Numerical errors */
		}

		map.put(link, newWeight);
	}

	return MapTransformer.getInstance(map);
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:31,代码来源:GraphUtils.java

示例5: getFailures

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/**
 * Generates the {@link Failure} occurrences for a single simulation run based on the given {@link BDD} and the
 * {@link ReliabilityFunction}s of its elements.
 * 
 * @param bdd
 *            the given bdd
 * @param functionTransformer
 *            the element to reliability function transformer
 * @return the failure occurrences for a single simulation run
 */
protected Set<Failure<T>> getFailures(BDD<T> bdd, Transformer<T, ReliabilityFunction> functionTransformer) {
	SortedSet<Failure<T>> failureTimes = new TreeSet<>();
	Set<T> elements = bdd.getVariables();
	for (T element : elements) {
		ReliabilityFunction relFunction = functionTransformer.transform(element);
		InverseFunction inverse = new InverseFunction(relFunction);
		double x = inverse.getY(random.nextDouble());
		Failure<T> failureTime = new Failure<>(element, x);
		failureTimes.add(failureTime);
	}
	return failureTimes;
}
 
开发者ID:felixreimann,项目名称:jreliability,代码行数:23,代码来源:BDDTTRFSimulative.java

示例6: createHomogenousPairs

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
static public <T> Pair<T,T>[] createHomogenousPairs(Collection<T> inputs, Transformer<Pair<T,T>,String> joiner) {
	List<Pair<T,T>> result = new ArrayList<Pair<T,T>>();
	
	List<T> list = new ArrayList<T>(inputs);
	int n = list.size();
	if (n > 1) {
		for (int a = 0; a < n; ++a) {
			T aa = list.get(a);
			for (int b = a+1; b < n; ++b) {
				T bb = list.get(b);
				
				Pair<T,T> pair = new Pair<T,T>(aa, bb, null);
				String name = joiner.transform(pair);
					
				result.add(new Pair<T,T>(aa, bb, name));
				
				pair = new Pair<T,T>(bb, aa, null);
				name = joiner.transform(pair);
				
				result.add(new Pair<T,T>(bb, aa, name));
			}
		}
	}
	
	@SuppressWarnings("unchecked")
	Pair<T,T>[] pairs = (Pair<T,T>[]) Array.newInstance(Pair.class, result.size());
	pairs = result.toArray(pairs);
	
	return pairs;
}
 
开发者ID:kddart,项目名称:kdxplore,代码行数:31,代码来源:Pair.java

示例7: getPathWeight

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/** Returns the weight of a path given the sequence of edges.
 * 
 * @param <E> Class type for edges
 * @param path Sequence of edges
 * @param nev Object responsible for returning weights for edges
 * @return Path weight */
public static <E> double getPathWeight(List<E> path, Transformer<E, Double> nev)
{
	double pathWeight = 0;
	if (nev == null) nev = getEdgeWeightTransformer(null);
	for (E edge : path)
		pathWeight += nev.transform(edge);

	return pathWeight;
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:16,代码来源:GraphUtils.java

示例8: simplifyGraph

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/** Given an input graph that may contain multiple edges between some vertex pairs, returns a new graph where only appears, for each vertex pair, the edge having the lowest weight (edges whose weight is equal to {@code Double.MAX_VALUE} are excluded). Ties are broken arbitrarely.
 * 
 * <p><b>Important</b>: Returned graph is not backed in the input one, so changes will not be reflected on it.
 * 
 * @param <V> Vertex type
 * @param <E> Edge type
 * @param graph Graph representing the network
 * @param nev Object responsible for returning weights for edges
 * @return Copy of the input graph with at most an edge between each vertex pair */
public static <V, E> Graph<V, E> simplifyGraph(Graph<V, E> graph, Transformer<E, Double> nev)
{
	Collection<V> vertices = graph.getVertices();
	Set<E> edgesToMaintain = new LinkedHashSet<E>();
	for (V originVertex : vertices)
	{
		for (V destinationVertex : vertices)
		{
			if (originVertex == destinationVertex) continue;

			Collection<E> edges = graph.findEdgeSet(originVertex, destinationVertex);
			if (edges.isEmpty()) continue;

			E bestEdge = null;
			double bestWeight = Double.MAX_VALUE;

			for (E edge : edges)
			{
				double weight_thisEdge = nev.transform(edge);
				if (weight_thisEdge < bestWeight)
				{
					bestWeight = weight_thisEdge;
					bestEdge = edge;
				}
			}

			if (bestEdge != null) edgesToMaintain.add(bestEdge);
		}
	}

	return JUNGUtils.filterGraph(graph, null, null, edgesToMaintain, null);
}
 
开发者ID:girtel,项目名称:Net2Plan,代码行数:42,代码来源:GraphUtils.java

示例9: paintIconForVertex

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
public void paintIconForVertex(RenderContext<V,E> rc, V v, Layout<V,E> layout) {
	
    Point2D p = layout.transform(v);
    p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
    float x = (float)p.getX();
    float y = (float)p.getY();

    GraphicsDecorator g = rc.getGraphicsContext();
    boolean outlineImages = false;
    Transformer<V,Icon> vertexIconFunction = rc.getVertexIconTransformer();
    
    if(vertexIconFunction instanceof DemoVertexIconTransformer) {
        outlineImages = ((DemoVertexIconTransformer<V>)vertexIconFunction).isOutlineImages();
    }
    Icon icon = vertexIconFunction.transform(v);
    if(icon == null || outlineImages) {
        
        Shape s = AffineTransform.getTranslateInstance(x,y).
            createTransformedShape(rc.getVertexShapeTransformer().transform(v));
        paintShapeForVertex(rc, v, s);
    }
    if(icon != null) {
        int xLoc = (int) (x - icon.getIconWidth()/2);
        int yLoc = (int) (y - icon.getIconHeight()/2);
        icon.paintIcon(rc.getScreenDevice(), g.getDelegate(), xLoc, yLoc);
    }
}
 
开发者ID:marcvanzee,项目名称:mdp-plan-revision,代码行数:28,代码来源:VertexImageShaperDemo.java

示例10: evaluate

import org.apache.commons.collections15.Transformer; //导入方法依赖的package包/类
/**
 * Evaluates the BDD to determine the top event.
 * 
 * @param <T>
 *            the type of the variables
 * @param bdd
 *            the bdd
 * @param transformer
 *            the transformer
 * @param upSort
 *            the sorted bdd nodes
 * @return the top event
 */
protected static <T> double evaluate(BDD<T> bdd, Transformer<T, Double> transformer, Set<BDD<T>> upSort) {
	Map<T, Double> values = new HashMap<>();
	HashMap<BDD<T>, Double> bddToDouble = new HashMap<>();

	for (BDD<T> tmpBdd : upSort) {

		T t = tmpBdd.var();
		Double r = values.get(t);
		if (r == null) {
			r = transformer.transform(t);
			values.put(t, r);
		}

		double high;
		double low;
		BDD<T> highBdd = tmpBdd.high();
		if (highBdd.isOne()) {
			high = 1.0;
		} else if (highBdd.isZero()) {
			high = 0.0;
		} else {
			high = bddToDouble.get(highBdd);
		}
		highBdd.free();

		BDD<T> lowBdd = tmpBdd.low();
		if (lowBdd.isOne()) {
			low = 1.0;
		} else if (lowBdd.isZero()) {
			low = 0.0;
		} else {
			low = bddToDouble.get(lowBdd);
		}
		lowBdd.free();

		// Shannon decomposition
		double y = r * high + (1 - r) * low;

		bddToDouble.put(tmpBdd, y);
	}

	double x = bddToDouble.get(bdd);

	for (BDD<T> freeBdd : bddToDouble.keySet()) {
		freeBdd.free();
	}

	return x;
}
 
开发者ID:felixreimann,项目名称:jreliability,代码行数:63,代码来源:BDDs.java


注:本文中的org.apache.commons.collections15.Transformer.transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。