當前位置: 首頁>>代碼示例>>Java>>正文


Java IMonitorSolution類代碼示例

本文整理匯總了Java中org.chocosolver.solver.search.loop.monitors.IMonitorSolution的典型用法代碼示例。如果您正苦於以下問題:Java IMonitorSolution類的具體用法?Java IMonitorSolution怎麽用?Java IMonitorSolution使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IMonitorSolution類屬於org.chocosolver.solver.search.loop.monitors包,在下文中一共展示了IMonitorSolution類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: solve

import org.chocosolver.solver.search.loop.monitors.IMonitorSolution; //導入依賴的package包/類
public void solve() {
	GraphModel model = new GraphModel();
	IntVar totalCost = model.intVar("obj", lb, ub, true);
	// graph var domain
	UndirectedGraph GLB = new UndirectedGraph(model,n,SetType.LINKED_LIST,true);
	UndirectedGraph GUB = new UndirectedGraph(model,n,SetType.BIPARTITESET,true);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (dist[i][j] != -1 && !(dMax[i] == 1 && dMax[j] == 1)) {
				GUB.addEdge(i, j); // possible edge
			}
		}
	}
	UndirectedGraphVar graph = model.graphVar("G", GLB, GUB);
	IntVar[]degrees = model.degrees(graph);
	for (int i = 0; i < n; i++) {
		model.arithm(degrees[i], "<=", dMax[i]).post();
	}

	// degree constrained-minimum spanning tree constraint
	model.dcmst(graph,degrees,totalCost,dist,2).post();

	final GraphSearch mainSearch = new GraphSearch(graph, dist);
	// find the first solution by selecting cheap edges
	mainSearch.configure(GraphSearch.MIN_COST);
	Solver s = model.getSolver();
	// then select the most expensive ones (fail first principle, with last conflict)
	s.plugMonitor((IMonitorSolution) () -> {
           mainSearch.useLastConflict();
           mainSearch.configure(GraphSearch.MIN_P_DEGREE);
           System.out.println("Solution found : "+totalCost);
       });
	// bottom-up optimization : find a first solution then reach the global minimum from below
	s.setSearch(new ObjectiveStrategy(totalCost, OptimizationPolicy.BOTTOM_UP), mainSearch);
	s.limitSolution(2); // therefore there is at most two solutions
	long TIMELIMIT = 300000;
	s.limitTime(TIMELIMIT); // time limit

	// find optimum
	model.setObjective(Model.MINIMIZE,totalCost);
	while (s.solve()){
		System.out.println(totalCost);
	}

	if (s.getSolutionCount() == 0 && s.getTimeCount() < TIMELIMIT/1000) {
		throw new UnsupportedOperationException("Provided instances are feasible!");
	}
	String output = instance+";"+s.getSolutionCount()+";"+s.getBestSolutionValue()+";"
			+s.getNodeCount()+";"+s.getFailCount()+";"+s.getTimeCount()+";\n";
	write(output,OUT_PUT_FILE,false);
}
 
開發者ID:chocoteam,項目名稱:choco-graph,代碼行數:52,代碼來源:DCMST.java


注:本文中的org.chocosolver.solver.search.loop.monitors.IMonitorSolution類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。