「java生产图论」java图的实现

博主:adminadmin 2022-11-24 08:16:08 48

本篇文章给大家谈谈java生产图论,以及java图的实现对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java 最小生成树

public class AbstractGraphV

{

    public AbstractGraph(List?extends Edge edges, ListVvertices)

    {

        

    }

    public static class Edge

    {

        

    }

}

public class WeightedGraph extends AbstractGraphFloat

{

    public WeightedGraph(ListWeightedEdge edges, ListFloat vertices)

    {

        super(edges, vertices);

    }

    public static class WeightedEdge extends Edge

    {

        

    }

}

试试这种?

java怎么生成折线图,传入月份(1,2,3)生产数量(100,200,300),然后生成一个折线图,最好是曲线图,谢

按照你的要求编写的折线图程序如下:生成的图片放在D盘根目录下,文件名是testline.png

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartPanel;

import org.jfree.chart.ChartUtilities;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.NumberAxis;

import org.jfree.chart.plot.CategoryPlot;

import org.jfree.chart.plot.PlotOrientation;

import org.jfree.data.category.DefaultCategoryDataset;

import org.jfree.ui.ApplicationFrame;

import org.jfree.ui.RefineryUtilities;

public class LineCharts extends ApplicationFrame {

public LineCharts(String s) {

super(s);

setContentPane(createDemoLine());

}

public static void main(String[] args) {

LineCharts fjc = new LineCharts("折线图");

fjc.pack();

RefineryUtilities.centerFrameOnScreen(fjc);

fjc.setVisible(true);

}

// 生成显示图表的面板 public static JPanel createDemoLine() {

JFreeChart jfreechart = createChart(createDataset());

saveAsFile(jfreechart, "D://testline.png", 500, 300);

return new ChartPanel(jfreechart);

}

// 生成图表主对象JFreeChart public static JFreeChart createChart(DefaultCategoryDataset linedataset) {

//定义图表对象

JFreeChart chart = ChartFactory.createLineChart("LineChart", // chart title

"Time", // domain axis label

"Quantity", // range axis label

linedataset, // data

PlotOrientation.VERTICAL, // orientation

true, // include legend

true, // tooltips

false // urls

);

CategoryPlot plot = chart.getCategoryPlot();

// customise the range axis...

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

rangeAxis.setAutoRangeIncludesZero(true);

rangeAxis.setUpperMargin(1);

rangeAxis.setLabelAngle(Math.PI / 2.0);

return chart; }

//生成数据 public static DefaultCategoryDataset createDataset() {

DefaultCategoryDataset linedataset = new DefaultCategoryDataset();

// 各曲线名称

String series1 = "car";

// 横轴名称(列名称)

String type1 = "Jan";

String type2 = "Feb";

String type3 = "Mar";

linedataset.addValue(100, series1, type1); linedataset.addValue(200, series1, type2);

linedataset.addValue(300, series1, type3);

return linedataset; }

public static void saveAsFile(JFreeChart chart, String outputPath,

int weight, int height) {

FileOutputStream out = null;

try {

File outFile = new File(outputPath);

if (!outFile.getParentFile().exists()) {

outFile.getParentFile().mkdirs();

}

out = new FileOutputStream(outputPath);

// 保存为PNG文件

ChartUtilities.writeChartAsPNG(out, chart, 600, 350);

out.flush();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (out != null) {

try {

out.close();

} catch (IOException e) {

// do nothing

}

}

}

}

}

什么是JAVA开发环境,测试环境及生产环境

JAVA开发环境 这是开发人员用的环境 数据不真实

测试环境是测试人员用的环境 数据无限接近真实

生产环境 是 广大客户使用的环境。也就是运营了

重要性关系:开发环境测试环境生产环境

java中的算法,一共有多少种,哪几种,怎么分类。

就好比问,汉语中常用写作方法有多少种,怎么分类。

算法按用途分,体现设计目的、有什么特点

算法按实现方式分,有递归、迭代、平行、序列、过程、确定、不确定等等

算法按设计范型分,有分治、动态、贪心、线性、图论、简化等等

作为图灵完备的语言,理论上”Java语言“可以实现所有算法。

“Java的标准库'中用了一些常用数据结构和相关算法.

像apache common这样的java库中又提供了一些通用的算法

求图论算法java实现

求图论算法java实现

package test;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Comparator;

import java.util.HashMap;

import java.util.Map;

import java.util.PriorityQueue;

import java.util.Queue;

 

public class MinSpanningTree {

    class Edge {//内部类定义边的数据结果

        int u, v, weight;

    }

 

    ArrayListedge Edges = new ArrayListedge();

    Mapinteger, integer="" nodeFather = new HashMapinteger, integer=""();

    int cnt = 0, nodeCnt = 0;

 

    public MinSpanningTree(String path) {

        try {

 

            BufferedReader br = new BufferedReader(new FileReader(path));

            String str;

            String[] strArray;

 

            while ((str = br.readLine()) != null) {

                strArray = str.split("\\s");

                Edges.add(cnt, new Edge());

                Edges.get(cnt).u = Integer.parseInt(strArray[0]);

                Edges.get(cnt).v = Integer.parseInt(strArray[1]);

                Edges.get(cnt).weight = Integer.parseInt(strArray[2]);

                if (!nodeFather.containsKey(Edges.get(cnt).u)) {

                    nodeFather.put(Edges.get(cnt).u, Edges.get(cnt).u);//初始化,father[i]=i;

                    ++nodeCnt;

                }

                if (!nodeFather.containsKey(Edges.get(cnt).v)) {

                    nodeFather.put(Edges.get(cnt).v, Edges.get(cnt).v);

                    ++nodeCnt;

                }

                ++cnt;

            }

            br.close();

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

 

    public boolean union(int u, int v) {//并操作

        int a = find(u);

        int b = find(v);

        if (a != b) {

            nodeFather.put(a, b);

            return true;

        }

        return false;

    }

 

    public int find(int x) {//查操作

        if (x != nodeFather.get(x)) {

            nodeFather.put(x, find(nodeFather.get(x)));

        }

        return nodeFather.get(x);

    }

 

    public ArrayListedge getMinSpanningTree() {

        ArrayListedge result = new ArrayListedge();

        Queueedge FsQueue = new PriorityQueueedge(1000,//设置优先队列,使按边权值从小到大排序

                new Comparatoredge() {

                    public int compare(Edge EdgeOne, Edge EdgeTwo) {

                        if (EdgeOne.weight  EdgeTwo.weight)

                            return 1;

                        else if (EdgeOne.weight  EdgeTwo.weight)

                            return -1;

                        else

                            return 0;

                    }

                });

 

        for (int i = 0; i  cnt; ++i) {

            FsQueue.add(Edges.get(i));

        }

 

        while (!FsQueue.isEmpty()) {//遍历每一条边

            Edge Edge = FsQueue.poll();

            if (union(Edge.u, Edge.v)) {

                result.add(Edge);

            } else {

                continue;

            }

        }

        return result;

    }

 

    public static void main(String[] args) {

        MinSpanningTree mstree = new MinSpanningTree("c:/treedata.txt");

        ArrayListedge result = mstree.getMinSpanningTree();

        for (int i = 0; i  result.size(); ++i) {

            System.out.println(result.get(i).u + " " + result.get(i).v + " "+ result.get(i).weight);

        }

    }

}

java生产图论的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java图的实现、java生产图论的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-24,除非注明,否则均为首码项目网原创文章,转载请注明出处。