我目前正致力于实现A*算法,两个节点之间的距离不规则.包含节点的图是定向和加权图.每个节点连接到至少一个其他节点,也可以存在具有不同距离的对称连接.节点只不过是一个标签,不包含任何特殊信息
我需要的是一种启发式方法,以确定从任何节点A到另一个节点B的最短路径尽可能准确.我尝试使用一种启发式方法来返回到节点最近邻居的距离,但当然这并不像没有启发式算法那样有效(= Dijkstra).
我对A*算法的实现主要包括2个类,算法本身的类(AStar)和节点(Node)的类.该代码主要基于Wikipedia伪代码.
AStar.javapublic class AStar {
private AStar() {}
private static Node[] reconstructPath(Map<Node, Node> paths, Node current) {
List<Node> path = new ArrayList<Node>();
path.add(0, current);
while (paths.containsKey(current)) {
current = paths.get(current);
path.add(0, current);
}
return path.toArray(new Node[0]);
}
public static Node[] calculate(Node start, Node target, IHeuristic heuristic) {
List<Node> closed = new ArrayList<Node>();
PriorityQueue<Node> open = new PriorityQueue<Node>();
Map<Node, Double> g_score = new HashMap<Node, Double>();
Map<Node, Double> f_score = new …Run Code Online (Sandbox Code Playgroud) 我在设置字体时遇到问题JMenuBar.我个人不喜欢粗体字体Java框架默认使用,所以我试图通过使用这样的东西来改变它:
public class MyFrame extends javax.swing.JFrame {
public MyFrame() {
JMenuBar menuBar = new JMenuBar();
menuBar.setFont(new Font("sans-serif", Font.PLAIN, 12));
setJMenuBar(menuBar);
setSize(600, 400);
// add some menus to the menu bar
menuBar.add(new JMenu("Foo"));
menuBar.add(new JMenu("Bar"));
menuBar.add(new JMenu("Baz"));
menuBar.add(new JMenu("Qux"));
setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,该行menuBar.setFont(...)设置组件menuBar使用的字体.但是当我实例化其中一个框架时,默认字体根本没有改变,即使我把字体的大小设置为30也没有.
我感谢任何有关这方面的帮助.
你好,我制作了一个程序,可以将字符串突出显示到 webview(android) 中,我坚持用这段代码替换有颜色的字符串
String[] arr = "LION SAVANA".split(" ");//i split textview string to have words (here we suppose that user entered : "lion savana"
String finalText = "the lion is a species of mamifer living into the savana"
for (String ss : arr) {
if (ss.length() > 2) {
ss = ss.replace("*","");
finalText = finalText.replaceAll("(?i)" + ss, "<b style = \"color:#2575ff\";>" + ss + "</b>");//finally here i replace all lion or savana occurrences by blue ones -> but i not …Run Code Online (Sandbox Code Playgroud) java ×3
a-star ×1
algorithm ×1
heuristics ×1
jmenu ×1
jmenubar ×1
path-finding ×1
regex ×1
replace ×1
swing ×1