All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.opendse.realtime.et.qcqp.MyConflictRefinementDeletion Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
/*******************************************************************************
 * Copyright (c) 2015 OpenDSE
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *******************************************************************************/
package net.sf.opendse.realtime.et.qcqp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.sf.jmpi.main.MpProblem;
import net.sf.jmpi.main.MpResult;
import net.sf.jmpi.main.MpSolver;
import net.sf.opendse.model.Specification;
import net.sf.opendse.realtime.et.SolverProvider;
import net.sf.opendse.realtime.et.graph.TimingDependency;
import net.sf.opendse.realtime.et.graph.TimingDependencyPriority;
import net.sf.opendse.realtime.et.graph.TimingElement;
import net.sf.opendse.realtime.et.graph.TimingGraph;
import edu.uci.ics.jung.graph.util.Pair;

public class MyConflictRefinementDeletion implements MyConflictRefinement {
	
	protected final SolverProvider solverProvider;
	protected final boolean rateMonotonic;

	public MyConflictRefinementDeletion(SolverProvider solverProvider, boolean rateMonotonic) {
		super();
		this.solverProvider = solverProvider;
		this.rateMonotonic = rateMonotonic;
	}

	public Set find(TimingGraph tg, Specification impl) {
		Set iis = new HashSet();

		for (TimingElement te : tg.getVertices()) {
			iis.add(te);
		}

		return find(tg, impl, iis);
	}

	public Set find(TimingGraph tg, Specification impl, Set predef) {

		Set iis = new HashSet(predef);

		List teList = new ArrayList(predef);

		Map> removed = new HashMap>();
		Double lastE = 0.0;

		for (TimingElement te : teList) {
			System.out.print("conflict refinement " + te);
			lastE = te.getAttribute("e");
			te.setAttribute("e", 0.0);

			for (TimingDependency td : tg.getIncidentEdges(te)) {
				if (td instanceof TimingDependencyPriority) {
					removed.put((TimingDependencyPriority) td,
							new Pair(tg.getSource(td), tg.getDest(td)));
				}
			}
			for (TimingDependency td : removed.keySet()) {
				tg.removeEdge(td);
			}

			MyEncoder encoder = new MyEncoder();
			MpProblem problem = encoder.encode(tg);
			// System.out.println(problem);

			MpSolver solver = solverProvider.get();
			solver.add(problem);
			
			MpResult result = solver.solve();

			System.out.println(" " + ((result == null ? "infeasible" : "feasible")));

			// System.out.println("without "+te+" : "+result);

			if (result != null) {
				// this is part of the IIS, reset timing graph
				te.setAttribute("e", lastE);

				for (TimingDependencyPriority td : removed.keySet()) {
					Pair endpoints = removed.get(td);
					tg.addEdge(td, endpoints);
				}

			} else {
				iis.remove(te);

			}
			removed.clear();
		}

		return iis;

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy