├── data └── data.xls ├── docs └── projects2016.pdf ├── bin └── caiconghuai-networks.jar ├── networks ├── src │ └── main │ │ ├── resources │ │ └── data.xls │ │ └── java │ │ └── edu │ │ └── hitsz │ │ ├── utils │ │ ├── Node.java │ │ ├── JXLUtils.java │ │ ├── CommonUtils.java │ │ └── GraphUtils.java │ │ └── view │ │ ├── robustness │ │ ├── randomtest │ │ │ ├── RandomAttackBlankPanel.java │ │ │ ├── RandomAttackTopPanel.java │ │ │ ├── RandomAttackLeftLNPanel.java │ │ │ ├── RandomAttackGraphAftPanel.java │ │ │ ├── RandomAttackLeftSNPanel.java │ │ │ ├── RandomAttackGraphBefPanel.java │ │ │ ├── RandomAttackFrame.java │ │ │ └── RandomAttackBottomPanel.java │ │ └── intentionaltest │ │ │ ├── IntentionalAttackBlankPanel.java │ │ │ ├── IntentionalAttackTopPanel.java │ │ │ ├── IntentionalAttackLeftLNPanel.java │ │ │ ├── IntentionalAttackGraphAftPanel.java │ │ │ ├── IntentionalAttackLeftSNPanel.java │ │ │ ├── IntentionalAttackGraphBefPanel.java │ │ │ ├── IntentionalAttackFrame.java │ │ │ └── IntentionalAttackBottomPanel.java │ │ ├── degreedistr │ │ └── DegreeDistributionPanel.java │ │ ├── MainFrame.java │ │ ├── MainGraphPanel.java │ │ └── MenuPanel.java └── pom.xml ├── .gitignore └── README.md /data/data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feiyutalk/mcnp/HEAD/data/data.xls -------------------------------------------------------------------------------- /docs/projects2016.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feiyutalk/mcnp/HEAD/docs/projects2016.pdf -------------------------------------------------------------------------------- /bin/caiconghuai-networks.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feiyutalk/mcnp/HEAD/bin/caiconghuai-networks.jar -------------------------------------------------------------------------------- /networks/src/main/resources/data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feiyutalk/mcnp/HEAD/networks/src/main/resources/data.xls -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/utils/Node.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.utils; 2 | 3 | public class Node { 4 | int number; 5 | int level; 6 | 7 | public Node(){ 8 | 9 | } 10 | 11 | public Node(int number, int level){ 12 | this.number = number; 13 | this.level = level; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackBlankPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import javax.swing.*; 4 | 5 | public class RandomAttackBlankPanel extends JPanel{ 6 | public static final int WIDTH = 665; 7 | public static final int HEIGHT = 450; 8 | } 9 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/intentionaltest/IntentionalAttackBlankPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.intentionaltest; 2 | 3 | import javax.swing.*; 4 | 5 | public class IntentionalAttackBlankPanel extends JPanel{ 6 | public static final int WIDTH = 665; 7 | public static final int HEIGHT = 450; 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | .settings/ 4 | *.db 5 | # Created by https://www.gitignore.io/api/maven 6 | 7 | ### Maven ### 8 | target/ 9 | pom.xml.tag 10 | pom.xml.releaseBackup 11 | pom.xml.versionsBackup 12 | pom.xml.next 13 | release.properties 14 | dependency-reduced-pom.xml 15 | buildNumber.properties 16 | .mvn/timing.properties 17 | .classpath 18 | .project 19 | .db 20 | logger/ 21 | 22 | # Exclude maven wrapper 23 | 24 | # End of https://www.gitignore.io/api/maven 25 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackTopPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | public class RandomAttackTopPanel extends JPanel{ 7 | 8 | public static final int WIDTH = RandomAttackFrame.WIDTH - RandomAttackLeftLNPanel.WIDTH; 9 | 10 | public static final int HEIGHT = 70; 11 | 12 | public static String attackNodeString = ""; 13 | 14 | private JLabel jlb = null; 15 | 16 | public static JTextField jtf = new JTextField(); 17 | 18 | public RandomAttackTopPanel(){ 19 | setLayout(null); 20 | 21 | jlb = new JLabel("nodes sequence:"); 22 | jlb.setFont(new Font("Times", 1, 15)); 23 | jlb.setBounds(20, 15, 150, 50); 24 | 25 | jtf.setFont(new Font("Times", 1, 15)); 26 | jtf.setBorder(null); 27 | jtf.setEditable(false); 28 | jtf.setBounds(150, 25, 1150, 29 | 30); 30 | 31 | this.add(jlb); 32 | this.add(jtf); 33 | } 34 | 35 | public static void addAttackNodesAndShow(int nodeNumber){ 36 | attackNodeString += (nodeNumber +" "); 37 | jtf.setText(attackNodeString); 38 | } 39 | 40 | public static void clear(){ 41 | attackNodeString = ""; 42 | jtf.setText(attackNodeString); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/intentionaltest/IntentionalAttackTopPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.intentionaltest; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | public class IntentionalAttackTopPanel extends JPanel{ 7 | 8 | public static final int WIDTH = IntentionalAttackFrame.WIDTH - IntentionalAttackLeftLNPanel.WIDTH; 9 | 10 | public static final int HEIGHT = 70; 11 | 12 | public static String attackNodeString = ""; 13 | 14 | private JLabel jlb = null; 15 | 16 | public static JTextField jtf = new JTextField(); 17 | 18 | public IntentionalAttackTopPanel(){ 19 | setLayout(null); 20 | 21 | jlb = new JLabel("nodes sequences:"); 22 | jlb.setFont(new Font("Times", 1, 15)); 23 | jlb.setBounds(20, 15, 150, 50); 24 | 25 | jtf.setFont(new Font("Times", 1, 15)); 26 | jtf.setBorder(null); 27 | jtf.setEditable(false); 28 | jtf.setBounds(150, 25, 1150, 29 | 30); 30 | 31 | this.add(jlb); 32 | this.add(jtf); 33 | 34 | } 35 | 36 | public static void addAttackNodesAndShow(int nodeNumber){ 37 | attackNodeString += (nodeNumber +" "); 38 | jtf.setText(attackNodeString); 39 | } 40 | 41 | public static void clear(){ 42 | attackNodeString = ""; 43 | jtf.setText(attackNodeString); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/utils/JXLUtils.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.utils; 2 | 3 | import jxl.Cell; 4 | import jxl.Sheet; 5 | import jxl.Workbook; 6 | import jxl.read.biff.BiffException; 7 | 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.util.ArrayList; 13 | 14 | public class JXLUtils { 15 | /** 16 | * @param args 17 | * @throws IOException 18 | * @throws BiffException 19 | */ 20 | private JXLUtils(){ 21 | 22 | } 23 | 24 | public static ArrayList> readFile(String filename, int sheetNumber) throws BiffException, IOException { 25 | // TODO Auto-generated method stub 26 | ArrayList> list = new ArrayList>(); 27 | 28 | Workbook rwb = null; 29 | 30 | Cell cell = null; 31 | 32 | File file = new File(filename); 33 | 34 | InputStream input = new FileInputStream(file); 35 | 36 | rwb = Workbook.getWorkbook(input); 37 | 38 | Sheet sheet = rwb.getSheet(sheetNumber); 39 | 40 | for(int i = 0; i row = new ArrayList(); 42 | for(int j=0; j degrees; 14 | 15 | public void showDegreeDistribution(ArrayList degrees){ 16 | this.degrees = degrees; 17 | repaint(); 18 | } 19 | 20 | protected void paintComponent(Graphics g){ 21 | if(degrees == null) return; 22 | 23 | super.paintComponent(g); 24 | 25 | int width = getWidth(); 26 | int height = getHeight(); 27 | 28 | int interval = (width - 40) / degrees.size(); 29 | int individualWidth = (int)(((width - 40)/MainFrame.dataNumbers) * 0.6); 30 | 31 | int maxDegree = Collections.max(degrees); 32 | 33 | 34 | int x = 60; 35 | 36 | g.drawLine(10, height - 45, width-10, height - 45); 37 | 38 | for(int i = 0; i < degrees.size(); i++){ 39 | int barHeight = 40 | (int)(((double)degrees.get(i)/(double)maxDegree) * (height-75)); 41 | 42 | g.drawRect(x, height - 45 -barHeight, individualWidth, barHeight); 43 | 44 | g.drawString((1+i) + "", x, height - 30); 45 | 46 | g.drawString(degrees.get(i)+"", x, height - 45 -barHeight-10); 47 | 48 | x+=interval; 49 | } 50 | Color oldColor = g.getColor(); 51 | Font oldFont = g.getFont(); 52 | 53 | g.setFont(new Font("Times",1,15)); 54 | g.drawString("平均度数:"+GraphUtils.getAverageDegreeByDegrees(degrees), 55 | width-300, 20); 56 | } 57 | 58 | public Dimension getPreferredSize(){ 59 | return new Dimension(1300, 500); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/MainFrame.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view; 2 | 3 | import edu.hitsz.view.degreedistr.DegreeDistributionPanel; 4 | import edu.hitsz.view.robustness.intentionaltest.IntentionalAttackFrame; 5 | import edu.hitsz.view.robustness.randomtest.RandomAttackFrame; 6 | 7 | import javax.swing.*; 8 | import javax.swing.border.LineBorder; 9 | import java.awt.*; 10 | 11 | public class MainFrame extends JFrame{ 12 | /** 13 | * @param args 14 | */ 15 | private MenuPanel menuPanel = new MenuPanel(); 16 | 17 | public static MainGraphPanel graphPanel = new MainGraphPanel(); 18 | 19 | public static DegreeDistributionPanel degreeDistributionPanel = new DegreeDistributionPanel(); 20 | 21 | public static JFrame histogramFrame = new JFrame(); 22 | 23 | public static RandomAttackFrame randomAttackFrame = new RandomAttackFrame(); 24 | 25 | public static IntentionalAttackFrame intentionalAttackFrame = new IntentionalAttackFrame(); 26 | 27 | public static final String filename = "../data/data.xls"; 28 | 29 | public static final int dataNumbers = 55; 30 | 31 | public static int xlsNumbers = 0; 32 | 33 | public MainFrame(){ 34 | init(); 35 | } 36 | 37 | public static void main(String[] args) { 38 | MainFrame mainFrame = new MainFrame(); 39 | } 40 | 41 | public void init() { 42 | this.setLayout(null); 43 | 44 | graphPanel.setSize(1300, 900); 45 | graphPanel.setBounds(0, 0, 1300, 900); 46 | graphPanel.setBorder(new LineBorder(new Color(0,0,0))); 47 | 48 | menuPanel.setBounds(1300, 0, 49 | MenuPanel.WIDTH, MenuPanel.HEIGHT); 50 | menuPanel.setBorder(new LineBorder(new Color(0,0,0))); 51 | 52 | this.add(graphPanel); 53 | this.add(menuPanel); 54 | 55 | this.setLocation(30, 30); 56 | this.setSize(1800,900); 57 | this.setTitle("ComplexNetwork Project2016"); 58 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 59 | this.setResizable(false); 60 | this.setVisible(true); 61 | } 62 | 63 | public static void paintGraph(){ 64 | graphPanel.repaint(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /networks/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.iceslab 8 | neuclil-networks 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.6.1 17 | 18 | 1.8 19 | 1.8 20 | -Xlint 21 | true 22 | true 23 | 24 | 25 | 26 | maven-assembly-plugin 27 | 2.2 28 | 29 | 30 | 31 | edu.hitsz.view.MainFrame 32 | 33 | 34 | 35 | jar-with-dependencies 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | net.sourceforge.jexcelapi 46 | jxl 47 | 2.6.12 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/utils/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.utils; 2 | 3 | import jxl.read.biff.BiffException; 4 | 5 | import java.awt.*; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.Stack; 9 | 10 | public class CommonUtils { 11 | 12 | public static ArrayList> cloneMyArray(ArrayList> list){ 13 | ArrayList> listClone = new ArrayList>(); 14 | for(int i =0; i row = new ArrayList(); 16 | for(int j=0; j cloneMyStack(Stack stack){ 25 | Stack cloneStack = new Stack(); 26 | while(!stack.isEmpty()){ 27 | Integer item = stack.pop(); 28 | cloneStack.push(item); 29 | } 30 | return cloneStack; 31 | } 32 | 33 | public static ArrayList> readFile(String filename, int number){ 34 | ArrayList> datas = null; 35 | try { 36 | datas = JXLUtils.readFile(filename, number); 37 | } catch (BiffException e) { 38 | // TODO Auto-generated catch block 39 | e.printStackTrace(); 40 | } catch (IOException e) { 41 | // TODO Auto-generated catch block 42 | e.printStackTrace(); 43 | } 44 | return datas; 45 | } 46 | 47 | public static ArrayList createRandomLocations(int width, int height, int diameter) { 48 | int xInterval = width/8; 49 | int yInterval = height/7; 50 | ArrayList locations = new ArrayList(); 51 | for(int i =0; i<8; i++){ 52 | for(int j=0; j<7; j++){ 53 | int x = i*xInterval+(int)(Math.random()*xInterval); 54 | if(x<0) 55 | x=0+diameter; 56 | if(x>width-diameter) 57 | x=width-diameter; 58 | 59 | int y = j*yInterval+(int)(Math.random()*yInterval); 60 | if(y<0) 61 | y=0+diameter; 62 | if(y>height-diameter) 63 | y=height-diameter; 64 | Point point = new Point(x, y); 65 | locations.add(point); 66 | } 67 | } 68 | return locations; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackLeftLNPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import edu.hitsz.view.MainFrame; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.ArrayList; 8 | 9 | public class RandomAttackLeftLNPanel extends JPanel{ 10 | 11 | public static final int WIDTH = 270; 12 | public static final int HEIGHT = 280; 13 | public static final int BOTTOMWIDTH = 20; 14 | 15 | private double averageShortestPath ; 16 | private ArrayList removedNodesPath ; 17 | 18 | public RandomAttackLeftLNPanel(){ 19 | removedNodesPath = new ArrayList(); 20 | } 21 | 22 | public void addNodesAndShowLN(double averageShortestPath){ 23 | this.averageShortestPath = averageShortestPath; 24 | removedNodesPath.add(averageShortestPath); 25 | repaint(); 26 | } 27 | 28 | protected void paintComponent(Graphics g){ 29 | 30 | super.paintComponent(g); 31 | 32 | int width = getWidth(); 33 | int height = getHeight(); 34 | 35 | int interval = (width - 40) / MainFrame.dataNumbers; 36 | 37 | 38 | int maxAverageShortesPath ; 39 | maxAverageShortesPath = 10; 40 | 41 | int x = 20; 42 | 43 | Font oldFont = g.getFont(); 44 | g.setFont(new Font("Times", 1, 17)); 45 | g.drawString("average path length", 35, 30); 46 | g.setFont(oldFont); 47 | 48 | g.drawLine(10, height - BOTTOMWIDTH, width-30, height - BOTTOMWIDTH); 49 | 50 | g.drawLine(10, 50, 10, this.HEIGHT-BOTTOMWIDTH); 51 | 52 | int xLength = width-30 - 10; 53 | 54 | int yLength = this.HEIGHT-BOTTOMWIDTH - 50; 55 | 56 | g.drawString("0.2", (int)(xLength*0.2), height - BOTTOMWIDTH+10); 57 | 58 | g.drawString("0.4", (int)(xLength*0.4), height - BOTTOMWIDTH+10); 59 | 60 | g.drawString("0.6", (int)(xLength*0.6), height - BOTTOMWIDTH+10); 61 | 62 | g.drawString("0.8", (int)(xLength*0.8), height - BOTTOMWIDTH+10); 63 | 64 | g.drawString("1.0", (int)(xLength*1.0), height - BOTTOMWIDTH+10); 65 | 66 | 67 | g.drawString(maxAverageShortesPath+"", 20, (int)(50+yLength*(1.0-1.0))); 68 | 69 | g.drawString(maxAverageShortesPath/2+"", 20, (int)(50+yLength*(1.0-0.5))); 70 | 71 | for(int i = 0; i < removedNodesPath.size(); i++){ 72 | int barHeight = 73 | (int)(((double)removedNodesPath.get(i)/(double)maxAverageShortesPath) * (height-75)); 74 | Color oldColor = g.getColor(); 75 | g.setColor(Color.BLUE); 76 | g.fillOval(x, height - BOTTOMWIDTH -barHeight, 4, 4); 77 | g.setColor(oldColor); 78 | x+=interval; 79 | } 80 | } 81 | 82 | public void clear(){ 83 | removedNodesPath.clear(); 84 | this.repaint(); 85 | } 86 | 87 | public Dimension getPreferredSize(){ 88 | return new Dimension(1300, 500); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/intentionaltest/IntentionalAttackLeftLNPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.intentionaltest; 2 | 3 | import edu.hitsz.view.MainFrame; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.ArrayList; 8 | 9 | public class IntentionalAttackLeftLNPanel extends JPanel{ 10 | 11 | public static final int WIDTH = 270; 12 | public static final int HEIGHT = 280; 13 | public static final int BOTTOMWIDTH = 20; 14 | 15 | private double averageShortestPath ; 16 | private ArrayList removedNodesPath ; 17 | 18 | public IntentionalAttackLeftLNPanel(){ 19 | removedNodesPath = new ArrayList(); 20 | } 21 | 22 | public void addNodesAndShowLN(double averageShortestPath){ 23 | this.averageShortestPath = averageShortestPath; 24 | removedNodesPath.add(averageShortestPath); 25 | repaint(); 26 | } 27 | 28 | protected void paintComponent(Graphics g){ 29 | 30 | super.paintComponent(g); 31 | 32 | int width = getWidth(); 33 | int height = getHeight(); 34 | 35 | int interval = (width - 40) / MainFrame.dataNumbers; 36 | 37 | int maxAverageShortesPath ; 38 | maxAverageShortesPath = 10; 39 | 40 | int x = 20; 41 | 42 | Font oldFont = g.getFont(); 43 | g.setFont(new Font("Times", 1, 17)); 44 | g.drawString("average path length", 35, 30); 45 | g.setFont(oldFont); 46 | 47 | g.drawLine(10, height - BOTTOMWIDTH, width-30, height - BOTTOMWIDTH); 48 | 49 | g.drawLine(10, 50, 10, this.HEIGHT-BOTTOMWIDTH); 50 | 51 | int xLength = width-30 - 10; 52 | 53 | int yLength = this.HEIGHT-BOTTOMWIDTH - 50; 54 | 55 | g.drawString("0.2", (int)(xLength*0.2), height - BOTTOMWIDTH+10); 56 | 57 | g.drawString("0.4", (int)(xLength*0.4), height - BOTTOMWIDTH+10); 58 | 59 | g.drawString("0.6", (int)(xLength*0.6), height - BOTTOMWIDTH+10); 60 | 61 | g.drawString("0.8", (int)(xLength*0.8), height - BOTTOMWIDTH+10); 62 | 63 | g.drawString("1.0", (int)(xLength*1.0), height - BOTTOMWIDTH+10); 64 | 65 | 66 | g.drawString(maxAverageShortesPath+"", 20, (int)(50+yLength*(1.0-1.0))); 67 | 68 | g.drawString(maxAverageShortesPath/2+"", 20, (int)(50+yLength*(1.0-0.5))); 69 | 70 | for(int i = 0; i < removedNodesPath.size(); i++){ 71 | int barHeight = 72 | (int)(((double)removedNodesPath.get(i)/(double)maxAverageShortesPath) * (height-75)); 73 | Color oldColor = g.getColor(); 74 | g.setColor(Color.RED); 75 | g.fillOval(x, height - BOTTOMWIDTH -barHeight, 4, 4); 76 | g.setColor(oldColor); 77 | x+=interval; 78 | } 79 | } 80 | 81 | public void clear(){ 82 | removedNodesPath.clear(); 83 | this.repaint(); 84 | } 85 | 86 | public Dimension getPreferredSize(){ 87 | return new Dimension(1300, 500); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackGraphAftPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import edu.hitsz.utils.GraphUtils; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.ArrayList; 8 | 9 | public class RandomAttackGraphAftPanel extends JPanel{ 10 | public static final int WIDTH = 665; 11 | public static final int HEIGHT = 450; 12 | public static final int DIAMETER = 18; 13 | 14 | public static boolean isPaint = false; 15 | 16 | private ArrayList> datas = new ArrayList>(); 17 | private ArrayList locations = null; 18 | 19 | public RandomAttackGraphAftPanel(ArrayList locations){ 20 | this.locations = locations; 21 | } 22 | 23 | public void setDatas(ArrayList> datas){ 24 | this.datas = datas; 25 | } 26 | 27 | protected void paintComponent(Graphics g){ 28 | super.paintComponent(g); 29 | if(isPaint){ 30 | paintNodes(g); 31 | paintEdges(g, datas); 32 | paintNodesName(g); 33 | } 34 | } 35 | 36 | private void paintNodesName(Graphics g) { 37 | for(int i =0; i> datas) { 59 | for(int i = 0; i> datas = new ArrayList>(); 17 | private ArrayList locations = null; 18 | 19 | public IntentionalAttackGraphAftPanel(ArrayList locations){ 20 | this.locations = locations; 21 | } 22 | 23 | public void setDatas(ArrayList> datas){ 24 | this.datas = datas; 25 | } 26 | 27 | protected void paintComponent(Graphics g){ 28 | super.paintComponent(g); 29 | if(isPaint){ 30 | paintNodes(g); 31 | paintEdges(g, datas); 32 | paintNodesName(g); 33 | } 34 | } 35 | 36 | private void paintNodesName(Graphics g) { 37 | for(int i =0; i> datas) { 59 | for(int i = 0; i> datas; 19 | public ArrayList locations = new ArrayList(); 20 | 21 | public MainGraphPanel(){ 22 | locations = CommonUtils.createRandomLocations(this.WIDTH, this.HEIGHT, this.DIAMETER); 23 | } 24 | 25 | protected void paintComponent(Graphics g){ 26 | super.paintComponent(g); 27 | datas = readFile(MainFrame.filename, MainFrame.xlsNumbers); 28 | paintNodes(g); 29 | paintedges(g, datas); 30 | paintNodesName(g); 31 | } 32 | 33 | private void paintNodesName(Graphics g) { 34 | for(int i =0; i> datas) { 56 | for(int i = 0; i> readFile(String filename, int number){ 79 | ArrayList> datas = null; 80 | try { 81 | datas = JXLUtils.readFile(filename, number); 82 | } catch (BiffException e) { 83 | // TODO Auto-generated catch block 84 | e.printStackTrace(); 85 | } catch (IOException e) { 86 | // TODO Auto-generated catch block 87 | e.printStackTrace(); 88 | } 89 | return datas; 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackLeftSNPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import edu.hitsz.view.MainFrame; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.ArrayList; 8 | 9 | public class RandomAttackLeftSNPanel extends JPanel{ 10 | 11 | public static final int WIDTH = 270; 12 | public static final int HEIGHT = 280; 13 | public static final int BOTTOMWIDTH = 20; 14 | 15 | private int sizeOfLargestSubgraph ; 16 | private ArrayList removedNodesSize ; 17 | 18 | public RandomAttackLeftSNPanel(){ 19 | removedNodesSize = new ArrayList(); 20 | } 21 | 22 | public void addNodesAndShowSN(int sizeOfLargestSubgraph){ 23 | this.sizeOfLargestSubgraph = sizeOfLargestSubgraph; 24 | removedNodesSize.add(sizeOfLargestSubgraph); 25 | repaint(); 26 | } 27 | 28 | protected void paintComponent(Graphics g){ 29 | 30 | super.paintComponent(g); 31 | 32 | int width = getWidth(); 33 | int height = getHeight(); 34 | 35 | int interval = (width - 40) / MainFrame.dataNumbers; 36 | 37 | int maxSizeOfLargestSubgraph = MainFrame.dataNumbers; 38 | 39 | int x = 20; 40 | 41 | Font oldFont = g.getFont(); 42 | g.setFont(new Font("Times", 1, 17)); 43 | g.drawString("size of the largest subgraph", 25, 30); 44 | g.setFont(oldFont); 45 | 46 | g.drawLine(10, height - BOTTOMWIDTH, width-30, height - BOTTOMWIDTH); //X�� 47 | 48 | g.drawLine(10, 50, 10, this.HEIGHT-BOTTOMWIDTH); //Y�� 49 | 50 | int xLength = width-30 - 10; 51 | 52 | int yLength = this.HEIGHT-BOTTOMWIDTH - 50; 53 | 54 | g.drawString("0.2", (int)(xLength*0.2), height - BOTTOMWIDTH+10); 55 | 56 | g.drawString("0.4", (int)(xLength*0.4), height - BOTTOMWIDTH+10); 57 | 58 | g.drawString("0.6", (int)(xLength*0.6), height - BOTTOMWIDTH+10); 59 | 60 | g.drawString("0.8", (int)(xLength*0.8), height - BOTTOMWIDTH+10); 61 | 62 | g.drawString("1.0", (int)(xLength*1.0), height - BOTTOMWIDTH+10); 63 | 64 | 65 | g.drawString("1.0", 20, (int)(50+yLength*(1.0-1.0))); 66 | 67 | g.drawString("0.8", 20, (int)(50+yLength*(1.0-0.8))); 68 | 69 | g.drawString("0.6", 20, (int)(50+yLength*(1.0-0.6))); 70 | 71 | g.drawString("0.4", 20, (int)(50+yLength*(1.0-0.4))); 72 | 73 | g.drawString("0.2", 20, (int)(50+yLength*(1.0-0.2))); 74 | 75 | for(int i = 0; i < removedNodesSize.size(); i++){ 76 | int barHeight = 77 | (int)(((double)removedNodesSize.get(i)/(double)maxSizeOfLargestSubgraph) * (height-75)); 78 | Color oldColor = g.getColor(); 79 | g.setColor(Color.BLUE); 80 | g.fillRect(x, height - BOTTOMWIDTH -barHeight, 4, 4); 81 | g.setColor(oldColor); 82 | x+=interval; 83 | } 84 | } 85 | 86 | public void clear(){ 87 | removedNodesSize.clear(); 88 | this.repaint(); 89 | } 90 | 91 | public Dimension getPreferredSize(){ 92 | return new Dimension(1300, 500); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/intentionaltest/IntentionalAttackLeftSNPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.intentionaltest; 2 | 3 | import edu.hitsz.view.MainFrame; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.ArrayList; 8 | 9 | public class IntentionalAttackLeftSNPanel extends JPanel{ 10 | 11 | public static final int WIDTH = 270; 12 | public static final int HEIGHT = 280; 13 | public static final int BOTTOMWIDTH = 20; 14 | 15 | private int sizeOfLargestSubgraph ; 16 | private ArrayList removedNodesSize ; 17 | 18 | public IntentionalAttackLeftSNPanel(){ 19 | removedNodesSize = new ArrayList(); 20 | } 21 | 22 | public void addNodesAndShowSN(int sizeOfLargestSubgraph){ 23 | this.sizeOfLargestSubgraph = sizeOfLargestSubgraph; 24 | removedNodesSize.add(sizeOfLargestSubgraph); 25 | repaint(); 26 | } 27 | 28 | protected void paintComponent(Graphics g){ 29 | 30 | super.paintComponent(g); 31 | 32 | int width = getWidth(); 33 | int height = getHeight(); 34 | 35 | int interval = (width - 40) / MainFrame.dataNumbers; 36 | 37 | int maxSizeOfLargestSubgraph = MainFrame.dataNumbers; 38 | 39 | int x = 20; 40 | 41 | Font oldFont = g.getFont(); 42 | g.setFont(new Font("Times", 1, 17)); 43 | g.drawString("size of the largest subgraph", 25, 30); 44 | g.setFont(oldFont); 45 | 46 | g.drawLine(10, height - BOTTOMWIDTH, width-30, height - BOTTOMWIDTH); 47 | 48 | g.drawLine(10, 50, 10, this.HEIGHT-BOTTOMWIDTH); 49 | 50 | int xLength = width-30 - 10; 51 | 52 | int yLength = this.HEIGHT-BOTTOMWIDTH - 50; 53 | 54 | g.drawString("0.2", (int)(xLength*0.2), height - BOTTOMWIDTH+10); 55 | 56 | g.drawString("0.4", (int)(xLength*0.4), height - BOTTOMWIDTH+10); 57 | 58 | g.drawString("0.6", (int)(xLength*0.6), height - BOTTOMWIDTH+10); 59 | 60 | g.drawString("0.8", (int)(xLength*0.8), height - BOTTOMWIDTH+10); 61 | 62 | g.drawString("1.0", (int)(xLength*1.0), height - BOTTOMWIDTH+10); 63 | 64 | 65 | g.drawString("1.0", 20, (int)(50+yLength*(1.0-1.0))); 66 | 67 | g.drawString("0.8", 20, (int)(50+yLength*(1.0-0.8))); 68 | 69 | g.drawString("0.6", 20, (int)(50+yLength*(1.0-0.6))); 70 | 71 | g.drawString("0.4", 20, (int)(50+yLength*(1.0-0.4))); 72 | 73 | g.drawString("0.2", 20, (int)(50+yLength*(1.0-0.2))); 74 | 75 | for(int i = 0; i < removedNodesSize.size(); i++){ 76 | int barHeight = 77 | (int)(((double)removedNodesSize.get(i)/(double)maxSizeOfLargestSubgraph) * (height-75)); 78 | Color oldColor = g.getColor(); 79 | g.setColor(Color.RED); 80 | g.fillRect(x, height - BOTTOMWIDTH -barHeight, 4, 4); 81 | g.setColor(oldColor); 82 | x+=interval; 83 | } 84 | } 85 | 86 | public void clear(){ 87 | removedNodesSize.clear(); 88 | this.repaint(); 89 | } 90 | 91 | public Dimension getPreferredSize(){ 92 | return new Dimension(1300, 500); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Modeling Of Complex Networks Project 2 | 3 | [![CircleCI](https://img.shields.io/circleci/project/github/RedSparr0w/node-csgo-parser.svg)]() [![Packagist](https://img.shields.io/badge/language-Java-green.svg)]() 4 | ## Description 5 | 6 | We have done an investigation on the connections in our class, and three corresponding social networks under different conditions (i.e., knowing someone’s name, knowing someone’s hometown, 7 | 8 | and knowing someone’s dialect) are formulated. Please download the data from our assigned FTP. 9 | 10 | (1) Perform some computer simulations (by using whatever computer software or programming language) 11 | on the three graphs to analyze the network properties (such as node-degree distribution, average shortest 12 | path-length, clustering coefficient, etc.) and dynamical behaviors (such as robustness against intentional 13 | attack and random attack, etc.). 14 | 15 | (2) Calculate the node coreness in the three graphs; 16 | 17 | (3) Draw necessary figures and/or tables to demonstrate your simulation results and to support your 18 | observations; 19 | 20 | (4) To have extra bonus, you can develop a small system (including friendly interfaces, or graphic 21 | demonstrations) to show the layout of the networks of our class. 22 | 23 | To see full project requirement : [Project Requirment[pdf]](https://github.com/neuclil/modeling-of-complex-networks/blob/master/docs/projects2016.pdf) 24 | 25 | ## Run 26 | 27 | - install JDK and add it's path to environment 28 | 29 | - cd /bin 30 | 31 | - run command: 32 | 33 | ```shell 34 | java -jar caiconghuai-networks.jar 35 | ``` 36 | 37 | ## Features 38 | 39 | - A Concise UI Interface. 40 | - Rich in Function. 41 | - Simple Code, Use Java's Drawing Pack. 42 | 43 | ## Preparation 44 | In this project, you need to known the basic knowledge about complex networks, such as Erdos-Renyi random graph model, Watts-Strogatz small-world network network model, Newman-Watts small-world model and so on. 45 | 46 | ## Property 47 | 48 | | Attribute | finished | 49 | | :--------------------------------: | :------: | 50 | | clustering coefficient | yes | 51 | | coreness | yes | 52 | | degree | yes | 53 | | shortest path | yes | 54 | | attention attack test | yes | 55 | | random attack test | yes | 56 | | node number/edge number statistics | yes | 57 | | size of the largest subgraph | yes | 58 | | average path length | yes | 59 | 60 | ## Display 61 | 62 | ![](https://media-1253434227.cos.ap-chengdu.myqcloud.com/2018-04-14-032347.jpg) 63 | 64 | ![](https://media-1253434227.cos.ap-chengdu.myqcloud.com/2018-04-14-032350.jpg) 65 | 66 | ![](https://media-1253434227.cos.ap-chengdu.myqcloud.com/2018-04-14-032352.jpg) 67 | 68 | ![](https://media-1253434227.cos.ap-chengdu.myqcloud.com/2018-04-14-032354.jpg) 69 | 70 | ## Contact 71 | 72 | Any questions please contact me. 73 | 74 | Email : caiconghuai@gmail.com 75 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackGraphBefPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import edu.hitsz.utils.GraphUtils; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.ArrayList; 8 | 9 | public class RandomAttackGraphBefPanel extends JPanel{ 10 | public static final int WIDTH = 665; 11 | public static final int HEIGHT = 450; 12 | public static final int DIAMETER = 18; 13 | public static int removedNode = -1; 14 | 15 | public static boolean isPaint = false; 16 | 17 | private ArrayList> datas = new ArrayList>(); 18 | private ArrayList locations = null; 19 | 20 | public RandomAttackGraphBefPanel(ArrayList locations){ 21 | this.locations = locations; 22 | } 23 | 24 | public void setDatas(ArrayList> datas){ 25 | this.datas = datas; 26 | } 27 | 28 | protected void paintComponent(Graphics g){ 29 | super.paintComponent(g); 30 | if(isPaint){ 31 | paintNodes(g); 32 | paintEdges(g, datas); 33 | paintNodesName(g); 34 | } 35 | } 36 | 37 | private void paintNodesName(Graphics g) { 38 | for(int i =0; i> datas) { 60 | for(int i = 0; i> datas = new ArrayList>(); 18 | private ArrayList locations = null; 19 | 20 | public IntentionalAttackGraphBefPanel(ArrayList locations){ 21 | this.locations = locations; 22 | } 23 | 24 | public void setDatas(ArrayList> datas){ 25 | this.datas = datas; 26 | } 27 | 28 | protected void paintComponent(Graphics g){ 29 | super.paintComponent(g); 30 | if(isPaint){ 31 | paintNodes(g); 32 | paintEdges(g, datas); 33 | paintNodesName(g); 34 | } 35 | } 36 | 37 | private void paintNodesName(Graphics g) { 38 | for(int i =0; i> datas) { 60 | for(int i = 0; i> initDatas ; 38 | 39 | public static ArrayList> befAttDatas; 40 | 41 | public static ArrayList> aftAttDatas; 42 | 43 | public RandomAttackFrame(){ 44 | 45 | changeDatas(); 46 | 47 | init(); 48 | 49 | addListener(); 50 | 51 | } 52 | 53 | private void addListener() { 54 | this.addWindowListener(new WindowAdapter() { 55 | @Override 56 | public void windowClosing(WindowEvent e){ 57 | 58 | RandomAttackFrame.testState = 0; 59 | 60 | randomAttackGraphPanelBef.removedNode = -1; 61 | 62 | randomAttackBottomPanel.clear(); 63 | 64 | randomAttackGraphPanelBef.clear(); 65 | randomAttackGraphPanelAft.clear(); 66 | 67 | randomAttackLeftLNPanel.clear(); 68 | randomAttackLeftSNPanel.clear(); 69 | 70 | randomAttackTopPanel.clear(); 71 | 72 | reset(); 73 | } 74 | }); 75 | } 76 | 77 | public static void reset(){ 78 | befAttDatas = CommonUtils.cloneMyArray(initDatas); 79 | aftAttDatas = CommonUtils.cloneMyArray(initDatas); 80 | } 81 | 82 | public static void changeDatas(){ 83 | initDatas = CommonUtils.readFile(MainFrame.filename, 84 | MainFrame.xlsNumbers); 85 | 86 | befAttDatas = CommonUtils.readFile(MainFrame.filename, 87 | MainFrame.xlsNumbers); 88 | 89 | aftAttDatas = CommonUtils.readFile(MainFrame.filename, 90 | MainFrame.xlsNumbers); 91 | } 92 | 93 | private void init() { 94 | 95 | jlbBef = new JLabel("攻击前"); 96 | jlbBef.setFont(new Font("Times", 1, 20)); 97 | jlbBef.setBounds(randomAttackLeftLNPanel.WIDTH+randomAttackGraphPanelBef.WIDTH/2-10, 80, 100, 20); 98 | 99 | jlbAft = new JLabel("攻击后"); 100 | jlbAft.setFont(new Font("Times", 1, 20)); 101 | jlbAft.setBounds(randomAttackLeftLNPanel.WIDTH+randomAttackGraphPanelBef.WIDTH+randomAttackGraphPanelAft.WIDTH/2, 102 | 80, 100, 20); 103 | 104 | randomAttackLeftLNPanel = new RandomAttackLeftLNPanel(); 105 | 106 | randomAttackLeftSNPanel = new RandomAttackLeftSNPanel(); 107 | 108 | randomAttackTopPanel = new RandomAttackTopPanel(); 109 | 110 | randomAttackBottomPanel = new RandomAttackBottomPanel(); 111 | 112 | ArrayList locations = CommonUtils.createRandomLocations(RandomAttackGraphBefPanel.WIDTH, 113 | RandomAttackGraphBefPanel.HEIGHT, RandomAttackGraphBefPanel.DIAMETER); 114 | 115 | randomAttackGraphPanelBef = new RandomAttackGraphBefPanel(locations); 116 | 117 | randomAttackGraphPanelAft = new RandomAttackGraphAftPanel(locations); 118 | 119 | randomAttackLeftLNPanel.setBounds(0, randomAttackLeftSNPanel.HEIGHT, 120 | RandomAttackLeftLNPanel.WIDTH, RandomAttackLeftLNPanel.HEIGHT); 121 | randomAttackLeftLNPanel.setBorder(new LineBorder(new Color(0,0,0))); 122 | 123 | randomAttackLeftSNPanel.setBounds(0,0, 124 | randomAttackLeftSNPanel.WIDTH, randomAttackLeftSNPanel.HEIGHT); 125 | randomAttackLeftSNPanel.setBorder(new LineBorder(new Color(0,0,0))); 126 | 127 | randomAttackTopPanel.setBounds(randomAttackLeftLNPanel.WIDTH,0, 128 | RandomAttackTopPanel.WIDTH, RandomAttackTopPanel.HEIGHT); 129 | randomAttackTopPanel.setBorder(new LineBorder(new Color(0,0,0))); 130 | 131 | randomAttackBottomPanel.setBounds(0, RandomAttackFrame.HEIGHT- RandomAttackBottomPanel.HEIGHT, 132 | RandomAttackBottomPanel.WIDTH, RandomAttackBottomPanel.HEIGHT); 133 | randomAttackBottomPanel.setBorder(new LineBorder(new Color(0,0,0))); 134 | 135 | randomAttackGraphPanelBef.setBounds(randomAttackLeftLNPanel.WIDTH, 136 | randomAttackTopPanel.HEIGHT+40, randomAttackGraphPanelBef.WIDTH, randomAttackGraphPanelBef.HEIGHT); 137 | randomAttackGraphPanelBef.setBorder(new LineBorder(new Color(0,0,0))); 138 | 139 | randomAttackGraphPanelAft.setBounds(randomAttackLeftLNPanel.WIDTH+randomAttackGraphPanelBef.WIDTH, 140 | randomAttackTopPanel.HEIGHT+40, randomAttackGraphPanelAft.WIDTH, randomAttackGraphPanelAft.HEIGHT); 141 | randomAttackGraphPanelAft.setBorder(new LineBorder(new Color(0,0,0))); 142 | 143 | 144 | testState = 0; 145 | 146 | this.add(jlbBef); 147 | this.add(jlbAft); 148 | 149 | this.add(randomAttackLeftLNPanel); 150 | this.add(randomAttackLeftSNPanel); 151 | this.add(randomAttackTopPanel); 152 | this.add(randomAttackBottomPanel); 153 | this.add(randomAttackGraphPanelBef); 154 | this.add(randomAttackGraphPanelAft); 155 | 156 | this.randomAttackLeftSNPanel.repaint(); 157 | this.randomAttackLeftLNPanel.repaint(); 158 | this.randomAttackBottomPanel.repaint(); 159 | 160 | 161 | 162 | this.setSize(RandomAttackFrame.WIDTH, 163 | RandomAttackFrame.HEIGHT); 164 | this.setLayout(null); 165 | this.setResizable(false); 166 | this.setTitle("random attack test"); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/intentionaltest/IntentionalAttackFrame.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.intentionaltest; 2 | 3 | import edu.hitsz.utils.CommonUtils; 4 | import edu.hitsz.view.MainFrame; 5 | 6 | import javax.swing.*; 7 | import javax.swing.border.LineBorder; 8 | import java.awt.*; 9 | import java.awt.event.WindowAdapter; 10 | import java.awt.event.WindowEvent; 11 | import java.util.ArrayList; 12 | 13 | public class IntentionalAttackFrame extends JFrame{ 14 | 15 | public static int testState ;//0???? 1????? 16 | 17 | public static final int WIDTH = 1630; 18 | 19 | public static final int HEIGHT = 900; 20 | 21 | private JLabel jlbBef = null; 22 | 23 | private JLabel jlbAft = null; 24 | 25 | public static IntentionalAttackLeftLNPanel intentionalAttackLeftLNPanel = null; 26 | 27 | public static IntentionalAttackLeftSNPanel intentionalAttackLeftSNPanel = null; 28 | 29 | public static IntentionalAttackTopPanel intentionalAttackTopPanel = null; 30 | 31 | public static IntentionalAttackBottomPanel intentionalAttackBottomPanel = null; 32 | 33 | public static IntentionalAttackGraphBefPanel intentionalAttackGraphBefPanel = null; 34 | 35 | public static IntentionalAttackGraphAftPanel intentionalAttackGraphAftPanel = null; 36 | 37 | public static ArrayList> initDatas ; 38 | 39 | public static ArrayList> befAttDatas; 40 | 41 | public static ArrayList> aftAttDatas; 42 | 43 | public IntentionalAttackFrame(){ 44 | 45 | changeDatas(); 46 | 47 | init(); 48 | 49 | addListener(); 50 | 51 | } 52 | 53 | private void addListener() { 54 | this.addWindowListener(new WindowAdapter() { 55 | @Override 56 | public void windowClosing(WindowEvent e){ 57 | 58 | IntentionalAttackFrame.testState = 0; 59 | 60 | 61 | intentionalAttackBottomPanel.clear(); 62 | 63 | intentionalAttackGraphBefPanel.clear(); 64 | intentionalAttackGraphAftPanel.clear(); 65 | 66 | intentionalAttackLeftLNPanel.clear(); 67 | intentionalAttackLeftSNPanel.clear(); 68 | 69 | intentionalAttackTopPanel.clear(); 70 | 71 | 72 | reset(); 73 | } 74 | }); 75 | } 76 | 77 | public static void reset(){ 78 | befAttDatas = CommonUtils.cloneMyArray(initDatas); 79 | aftAttDatas = CommonUtils.cloneMyArray(initDatas); 80 | } 81 | 82 | public static void changeDatas(){ 83 | initDatas = CommonUtils.readFile(MainFrame.filename, 84 | MainFrame.xlsNumbers); 85 | 86 | befAttDatas = CommonUtils.readFile(MainFrame.filename, 87 | MainFrame.xlsNumbers); 88 | 89 | aftAttDatas = CommonUtils.readFile(MainFrame.filename, 90 | MainFrame.xlsNumbers); 91 | } 92 | 93 | private void init() { 94 | 95 | jlbBef = new JLabel("攻击前"); 96 | jlbBef.setFont(new Font("Times", 1, 20)); 97 | jlbBef.setBounds(intentionalAttackLeftLNPanel.WIDTH+intentionalAttackGraphBefPanel.WIDTH/2-10, 80, 100, 20); 98 | 99 | jlbAft = new JLabel("攻击后"); 100 | jlbAft.setFont(new Font("Times", 1, 20)); 101 | jlbAft.setBounds(intentionalAttackLeftLNPanel.WIDTH+intentionalAttackGraphBefPanel.WIDTH+intentionalAttackGraphAftPanel.WIDTH/2, 102 | 80, 100, 20); 103 | 104 | intentionalAttackLeftLNPanel = new IntentionalAttackLeftLNPanel(); 105 | 106 | intentionalAttackLeftSNPanel = new IntentionalAttackLeftSNPanel(); 107 | 108 | intentionalAttackTopPanel = new IntentionalAttackTopPanel(); 109 | 110 | intentionalAttackBottomPanel = new IntentionalAttackBottomPanel(); 111 | 112 | ArrayList locations = CommonUtils.createRandomLocations(IntentionalAttackGraphBefPanel.WIDTH, 113 | IntentionalAttackGraphBefPanel.HEIGHT, IntentionalAttackGraphBefPanel.DIAMETER); 114 | 115 | intentionalAttackGraphBefPanel = new IntentionalAttackGraphBefPanel(locations); 116 | 117 | intentionalAttackGraphAftPanel = new IntentionalAttackGraphAftPanel(locations); 118 | 119 | intentionalAttackLeftLNPanel.setBounds(0, intentionalAttackLeftSNPanel.HEIGHT, 120 | IntentionalAttackLeftLNPanel.WIDTH, IntentionalAttackLeftLNPanel.HEIGHT); 121 | intentionalAttackLeftLNPanel.setBorder(new LineBorder(new Color(0,0,0))); 122 | 123 | intentionalAttackLeftSNPanel.setBounds(0,0, 124 | intentionalAttackLeftSNPanel.WIDTH, intentionalAttackLeftSNPanel.HEIGHT); 125 | intentionalAttackLeftSNPanel.setBorder(new LineBorder(new Color(0,0,0))); 126 | 127 | intentionalAttackTopPanel.setBounds(intentionalAttackLeftLNPanel.WIDTH,0, 128 | IntentionalAttackTopPanel.WIDTH, IntentionalAttackTopPanel.HEIGHT); 129 | intentionalAttackTopPanel.setBorder(new LineBorder(new Color(0,0,0))); 130 | 131 | intentionalAttackBottomPanel.setBounds(0, IntentionalAttackFrame.HEIGHT- IntentionalAttackBottomPanel.HEIGHT, 132 | IntentionalAttackBottomPanel.WIDTH, IntentionalAttackBottomPanel.HEIGHT); 133 | intentionalAttackBottomPanel.setBorder(new LineBorder(new Color(0,0,0))); 134 | 135 | intentionalAttackGraphBefPanel.setBounds(intentionalAttackLeftLNPanel.WIDTH, 136 | intentionalAttackTopPanel.HEIGHT+40, intentionalAttackGraphBefPanel.WIDTH, intentionalAttackGraphBefPanel.HEIGHT); 137 | intentionalAttackGraphBefPanel.setBorder(new LineBorder(new Color(0,0,0))); 138 | 139 | intentionalAttackGraphAftPanel.setBounds(intentionalAttackLeftLNPanel.WIDTH+intentionalAttackGraphBefPanel.WIDTH, 140 | intentionalAttackTopPanel.HEIGHT+40, intentionalAttackGraphAftPanel.WIDTH, intentionalAttackGraphAftPanel.HEIGHT); 141 | intentionalAttackGraphAftPanel.setBorder(new LineBorder(new Color(0,0,0))); 142 | 143 | 144 | testState = 0; 145 | 146 | this.add(jlbBef); 147 | this.add(jlbAft); 148 | 149 | this.add(intentionalAttackLeftLNPanel); 150 | this.add(intentionalAttackLeftSNPanel); 151 | this.add(intentionalAttackTopPanel); 152 | this.add(intentionalAttackBottomPanel); 153 | this.add(intentionalAttackGraphBefPanel); 154 | this.add(intentionalAttackGraphAftPanel); 155 | 156 | this.intentionalAttackLeftSNPanel.repaint(); 157 | this.intentionalAttackLeftLNPanel.repaint(); 158 | this.intentionalAttackBottomPanel.repaint(); 159 | 160 | 161 | 162 | this.setSize(IntentionalAttackFrame.WIDTH, 163 | IntentionalAttackFrame.HEIGHT); 164 | this.setLayout(null); 165 | this.setResizable(false); 166 | this.setTitle("intentional attack test"); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/MenuPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view; 2 | 3 | import edu.hitsz.utils.GraphUtils; 4 | import edu.hitsz.utils.JXLUtils; 5 | import jxl.read.biff.BiffException; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.awt.event.ItemEvent; 12 | import java.awt.event.ItemListener; 13 | import java.io.IOException; 14 | import java.util.ArrayList; 15 | 16 | 17 | public class MenuPanel extends JPanel{ 18 | 19 | public static final int WIDTH = 500; 20 | public static final int HEIGHT= 900; 21 | 22 | private JLabel jlbDatas = null; 23 | private JLabel jlbClus = null; 24 | private JLabel jlbNode = null; 25 | private JButton jbtClus = null; 26 | private JTextField jtfClus = null; 27 | private JLabel jlbCore = null; 28 | private JButton jbtCore = null; 29 | private JLabel jlbCoreNode = null; 30 | private JTextField jtfCore = null; 31 | private JLabel jlbCoreGraph = null; 32 | private JButton jbtCoreGraph = null; 33 | private JTextField jtfCoreGraph = null; 34 | private JLabel jlbDegree = null; 35 | private JLabel jlbDegreeNode = null; 36 | private JButton jbtDegreeDistr = null; 37 | private JButton jbtDegree = null; 38 | private JTextField jtfDegree = null; 39 | private JLabel jlbPath = null; 40 | private JButton jbtPath = null; 41 | private JTextField jtfPath = null; 42 | private JButton jbtDatas = null; 43 | private JButton jbtAveClus = null; 44 | private JTextField jtfAveClus = null; 45 | private JLabel jlbRbs = null; 46 | private JButton jbtRbsRd = null; 47 | private JButton jbtRbsIt = null; 48 | 49 | private JComboBox jcbDatas = null; 50 | private JComboBox jcbClusNodes = null; 51 | private JComboBox jcbCoreNodes = null; 52 | private JComboBox jcbDegreeNodes = null; 53 | 54 | public MenuPanel(){ 55 | setLayout(null); 56 | 57 | jlbDatas = new JLabel("选择数据集"); 58 | jlbDatas.setFont(new Font("Times",1, 15)); 59 | jlbDatas.setBounds(20, 20, 100, 50); 60 | 61 | jbtDatas = new JButton("画图"); 62 | jbtDatas.setFont(new Font("Times",1, 15)); 63 | jbtDatas.setBounds(350, 40, 70, 30); 64 | 65 | jlbClus = new JLabel("计算clustering coefficient:"); 66 | jlbClus.setFont(new Font("Times",1, 20)); 67 | jlbClus.setBounds(20, 80, 300, 50); 68 | 69 | jlbNode = new JLabel("选择顶点:"); 70 | jlbNode.setFont(new Font("Times",1, 15)); 71 | jlbNode.setBounds(20, 120, 100,50); 72 | 73 | jbtClus = new JButton("输出"); 74 | jbtClus.setFont(new Font("Times",1,15)); 75 | jbtClus.setBounds(200, 140, 70, 30); 76 | 77 | jtfClus = new JTextField(10); 78 | jtfClus.setEditable(false); 79 | jtfClus.setBounds(300, 140, 140, 30); 80 | 81 | jbtAveClus = new JButton("平均"); 82 | jbtAveClus.setFont(new Font("Times",1,15)); 83 | jbtAveClus.setBounds(200, 180, 70, 30); 84 | 85 | jtfAveClus = new JTextField(); 86 | jtfAveClus.setEditable(false); 87 | jtfAveClus.setBounds(300,180,140,30); 88 | 89 | 90 | 91 | 92 | jlbCore = new JLabel("计算coreness:"); 93 | jlbCore.setFont(new Font("Times",1, 20)); 94 | jlbCore.setBounds(20, 200, 300, 50); 95 | 96 | jlbCoreNode = new JLabel("选择顶点:"); 97 | jlbCoreNode.setFont(new Font("Times",1, 15)); 98 | jlbCoreNode.setBounds(20, 240, 100, 50); 99 | 100 | jbtCore = new JButton("输出"); 101 | jbtCore.setFont(new Font("Times", 1, 15)); 102 | jbtCore.setBounds(200, 260, 70, 30); 103 | 104 | jtfCore = new JTextField(10); 105 | jtfCore.setEditable(false); 106 | jtfCore.setBounds(300, 260, 140, 30); 107 | 108 | jlbCoreGraph = new JLabel("计算图的coreness:"); 109 | jlbCoreGraph.setFont(new Font("Times", 1, 15)); 110 | jlbCoreGraph.setBounds(20, 300, 200, 50); 111 | 112 | jbtCoreGraph = new JButton("输出"); 113 | jbtCoreGraph.setFont(new Font("Times", 1, 15)); 114 | jbtCoreGraph.setBounds(200, 330, 70, 30); 115 | 116 | jtfCoreGraph = new JTextField(10); 117 | jtfCoreGraph.setEditable(false); 118 | jtfCoreGraph.setBounds(300, 330, 140, 30); 119 | 120 | jlbDegree = new JLabel("计算Degree:"); 121 | jlbDegree.setFont(new Font("Times", 1, 20)); 122 | jlbDegree.setBounds(20, 370, 300, 50); 123 | 124 | jlbDegreeNode = new JLabel("选择顶点:"); 125 | jlbDegreeNode.setFont(new Font("Times", 1, 15)); 126 | jlbDegreeNode.setBounds(20, 410, 100, 50); 127 | 128 | jbtDegree = new JButton("输出"); 129 | jbtDegree.setFont(new Font("Times",1 , 15)); 130 | jbtDegree.setBounds(200, 430, 70, 30); 131 | 132 | jtfDegree = new JTextField(10); 133 | jtfDegree.setEditable(false); 134 | jtfDegree.setBounds(300, 430, 140, 30); 135 | 136 | jbtDegreeDistr = new JButton("显示度的分布"); 137 | jbtDegreeDistr.setFont(new Font("Times", 1, 15)); 138 | jbtDegreeDistr.setBounds(140, 480, 200, 40); 139 | 140 | jlbPath = new JLabel("计算平均最短路径:"); 141 | jlbPath.setFont(new Font("Times", 1, 20)); 142 | jlbPath.setBounds(20, 520, 300, 50); 143 | 144 | jbtPath = new JButton("输出"); 145 | jbtPath.setFont(new Font("Times", 1, 15)); 146 | jbtPath.setBounds(40, 580, 70, 30); 147 | 148 | jtfPath = new JTextField(10); 149 | jtfPath.setEditable(false); 150 | jtfPath.setBounds(140, 580, 140, 30); 151 | 152 | jlbRbs = new JLabel("测试图的鲁棒性:"); 153 | jlbRbs.setFont(new Font("Times", 1, 20)); 154 | jlbRbs.setBounds(20, 630, 300, 50); 155 | 156 | jbtRbsRd = new JButton("随机的攻击测试"); 157 | jbtRbsRd.setFont(new Font("Times", 1, 20)); 158 | jbtRbsRd.setBounds(60, 690, 300, 50); 159 | 160 | jbtRbsIt = new JButton("有意的攻击测试"); 161 | jbtRbsIt.setFont(new Font("Times",1 , 20)); 162 | jbtRbsIt.setBounds(60, 760, 300, 50); 163 | 164 | String strDatas[] ={"acquaintance", "hometown", "dialect"}; 165 | jcbDatas = new JComboBox(strDatas); 166 | jcbDatas.setBounds(150, 20, 150, 50); 167 | 168 | String strNodes[]={"1","2","3","4","5","6","7","8","9","10", 169 | "11","12","13","14","15","16","17","18","19","20", 170 | "21","22","23","24","25","26","27","28","29","30", 171 | "31","32","33","34","35","36","37","38","39","40", 172 | "41","42","43","44","45","46","47","48","49","50", 173 | "51","52","53","54","55"}; 174 | jcbClusNodes = new JComboBox(strNodes); 175 | JScrollPane jScrollPane = new JScrollPane(jcbClusNodes); 176 | jScrollPane.setBounds(120, 140, 50, 30); 177 | 178 | jcbCoreNodes = new JComboBox(strNodes); 179 | JScrollPane jScrollPane2 = new JScrollPane(jcbCoreNodes); 180 | jScrollPane2.setBounds(120, 260, 50, 30); 181 | 182 | jcbDegreeNodes = new JComboBox(strNodes); 183 | JScrollPane jScrollPane3 = new JScrollPane(jcbDegreeNodes); 184 | jScrollPane3.setBounds(120, 430,50,30); 185 | 186 | this.add(jlbDatas); 187 | this.add(jcbDatas); 188 | this.add(jlbClus); 189 | this.add(jlbNode); 190 | this.add(jScrollPane); 191 | this.add(jbtClus); 192 | this.add(jtfClus); 193 | this.add(jlbCore); 194 | this.add(jbtCore); 195 | this.add(jlbCoreNode); 196 | this.add(jScrollPane2); 197 | this.add(jtfCore); 198 | this.add(jlbCoreGraph); 199 | this.add(jbtCoreGraph); 200 | this.add(jtfCoreGraph); 201 | this.add(jlbDegree); 202 | this.add(jlbDegreeNode); 203 | this.add(jScrollPane3); 204 | this.add(jbtDegreeDistr); 205 | this.add(jbtDegree); 206 | this.add(jtfDegree); 207 | this.add(jlbPath); 208 | this.add(jbtPath); 209 | this.add(jtfPath); 210 | this.add(jbtDatas); 211 | this.add(jbtAveClus); 212 | this.add(jtfAveClus); 213 | this.add(jlbRbs); 214 | this.add(jbtRbsRd); 215 | this.add(jbtRbsIt); 216 | 217 | jbtDatas.addActionListener(new ActionListener() { 218 | 219 | @Override 220 | public void actionPerformed(ActionEvent e) { 221 | // TODO Auto-generated method stub 222 | String tableName = (String) jcbDatas.getSelectedItem(); 223 | if(tableName.equals("acquaintance")){ 224 | MainFrame.xlsNumbers = 0; 225 | MainFrame.paintGraph(); 226 | }else if(tableName.equals("hometown")){ 227 | MainFrame.xlsNumbers = 1; 228 | MainFrame.paintGraph(); 229 | }else{ 230 | MainFrame.xlsNumbers = 2; 231 | MainFrame.paintGraph(); 232 | } 233 | } 234 | }); 235 | 236 | jbtClus.addActionListener(new ActionListener() { 237 | 238 | @Override 239 | public void actionPerformed(ActionEvent e) { 240 | ArrayList> datas = getDatas(); 241 | String selectNum = (String) jcbClusNodes.getSelectedItem(); 242 | double clusteringCoefficient = GraphUtils.getClusteringCoefficient(datas, 243 | Integer.parseInt(selectNum)); 244 | jtfClus.setText(""+clusteringCoefficient); 245 | } 246 | }); 247 | 248 | jbtAveClus.addActionListener(new ActionListener() { 249 | 250 | @Override 251 | public void actionPerformed(ActionEvent e) { 252 | // TODO Auto-generated method stub 253 | ArrayList> datas = getDatas(); 254 | double aveClusteringCoefficient = GraphUtils.getAverageClusteringCoefficient(datas); 255 | jtfAveClus.setText(""+aveClusteringCoefficient); 256 | } 257 | }); 258 | 259 | jbtCore.addActionListener(new ActionListener() { 260 | 261 | @Override 262 | public void actionPerformed(ActionEvent e) { 263 | // TODO Auto-generated method stub 264 | ArrayList> datas = getDatas(); 265 | String selectNum = (String) jcbCoreNodes.getSelectedItem(); 266 | System.out.println(selectNum); 267 | int coreness = GraphUtils.getNodeCoreness(datas, Integer.parseInt(selectNum)); 268 | jtfCore.setText(""+coreness); 269 | } 270 | }); 271 | 272 | jbtCoreGraph.addActionListener(new ActionListener() { 273 | 274 | @Override 275 | public void actionPerformed(ActionEvent e) { 276 | // TODO Auto-generated method stub 277 | ArrayList> datas = getDatas(); 278 | int graphCoreness = GraphUtils.getGraphCoreness(datas); 279 | jtfCoreGraph.setText(""+graphCoreness); 280 | } 281 | 282 | }); 283 | 284 | jbtDegree.addActionListener(new ActionListener() { 285 | 286 | @Override 287 | public void actionPerformed(ActionEvent e) { 288 | ArrayList> datas = getDatas(); 289 | String selectNum = (String) jcbDegreeNodes.getSelectedItem(); 290 | int degree = GraphUtils.getNodeDegree(datas, Integer.parseInt(selectNum)); 291 | jtfDegree.setText(""+degree); 292 | } 293 | }); 294 | 295 | jbtPath.addActionListener(new ActionListener() { 296 | 297 | @Override 298 | public void actionPerformed(ActionEvent e) { 299 | ArrayList> datas = getDatas(); 300 | double path = GraphUtils.getAverageShortestPath(datas); 301 | jtfPath.setText(""+path); 302 | } 303 | }); 304 | 305 | jcbDatas.addItemListener(new ItemListener() { 306 | 307 | @Override 308 | public void itemStateChanged(ItemEvent e) { 309 | if(e.getStateChange() == ItemEvent.SELECTED){ 310 | String tableName = (String) jcbDatas.getSelectedItem(); 311 | if(tableName.equals("acquaintance")){ 312 | MainFrame.xlsNumbers = 0; 313 | MainFrame.randomAttackFrame.changeDatas(); 314 | }else if(tableName.equals("hometown")){ 315 | MainFrame.xlsNumbers = 1; 316 | MainFrame.randomAttackFrame.changeDatas(); 317 | }else{ 318 | MainFrame.xlsNumbers = 2; 319 | MainFrame.randomAttackFrame.changeDatas(); 320 | } 321 | 322 | } 323 | 324 | } 325 | }); 326 | 327 | jbtDegreeDistr.addActionListener(new ActionListener() { 328 | 329 | @Override 330 | public void actionPerformed(ActionEvent e) { 331 | // TODO Auto-generated method stub 332 | ArrayList> datas = getDatas(); 333 | ArrayList degrees = GraphUtils.getAllNodesDegree(datas); 334 | 335 | MainFrame.degreeDistributionPanel.showDegreeDistribution(degrees); 336 | 337 | MainFrame.histogramFrame.setVisible(true); 338 | } 339 | }); 340 | 341 | jbtRbsRd.addActionListener(new ActionListener() { 342 | 343 | @Override 344 | public void actionPerformed(ActionEvent e) { 345 | // TODO Auto-generated method stub 346 | MainFrame.randomAttackFrame.randomAttackBottomPanel.repaint(); 347 | MainFrame.randomAttackFrame.changeDatas(); 348 | MainFrame.randomAttackFrame.setVisible(true); 349 | } 350 | }); 351 | 352 | jbtRbsIt.addActionListener(new ActionListener() { 353 | 354 | @Override 355 | public void actionPerformed(ActionEvent e) { 356 | // TODO Auto-generated method stub 357 | MainFrame.intentionalAttackFrame.intentionalAttackBottomPanel.repaint(); 358 | MainFrame.intentionalAttackFrame.changeDatas(); 359 | MainFrame.intentionalAttackFrame.setVisible(true); 360 | } 361 | }); 362 | 363 | 364 | MainFrame.histogramFrame.add(MainFrame.degreeDistributionPanel); 365 | MainFrame.histogramFrame.pack(); 366 | MainFrame.histogramFrame.setTitle("degree distribution"); 367 | 368 | 369 | } 370 | 371 | 372 | private ArrayList> getDatas() { 373 | ArrayList> datas = null; 374 | try { 375 | datas = JXLUtils.readFile(MainFrame.filename, MainFrame.xlsNumbers); 376 | } catch (BiffException e1) { 377 | e1.printStackTrace(); 378 | } catch (IOException e1) { 379 | e1.printStackTrace(); 380 | } 381 | return datas; 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/utils/GraphUtils.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.utils; 2 | 3 | import java.util.*; 4 | 5 | public class GraphUtils { 6 | 7 | private GraphUtils(){ 8 | 9 | } 10 | 11 | public static int getNodeDegree(ArrayList> list, int index){ 12 | ArrayList row = list.get(index-1); 13 | int degree = 0; 14 | for(int i =0; i getAllNodesDegree(ArrayList> list){ 22 | ArrayList degrees = new ArrayList(); 23 | 24 | for(int i =0; i row = list.get(i); 26 | int degree = 0; 27 | for(int j=0; j> list){ 37 | ArrayList degrees = GraphUtils.getAllNodesDegree(list); 38 | int sumOfdegree = 0; 39 | for(int i=0; i degrees){ 46 | int sumOfdegree = 0; 47 | for(int i=0; i> list, int index){ 54 | int existingEdgesOfNeighbors = GraphUtils.existingEdgesOfNeighbors(list, index); 55 | int possiblyEdgesOfNeighbors = GraphUtils.possiblyEdgesOfNeighbors(list, index); 56 | if(possiblyEdgesOfNeighbors == 0) 57 | return 0; 58 | return 1.0*existingEdgesOfNeighbors/possiblyEdgesOfNeighbors; 59 | } 60 | 61 | public static int getNumberOfNeighbors(ArrayList> list, int index){ 62 | int number = 0; 63 | ArrayList row = list.get(index-1); 64 | for(int i=0; i> list, int index){ 72 | List neighbors = GraphUtils.getNeighbors(list, index); 73 | 74 | int existingEdges=0; 75 | // for(int i=0; i> list){ 97 | double sumOfClusteringCoefficient = 0; 98 | for(int i =0; i> list, int index){ 105 | int numberOfNeighbors = GraphUtils.getNumberOfNeighbors(list, index); 106 | return numberOfNeighbors*(numberOfNeighbors-1)/2; 107 | } 108 | 109 | public static List getNeighbors(ArrayList> list, int index){ 110 | List neighbors = new ArrayList(); 111 | ArrayList row = list.get(index-1); 112 | for(int i =0; i> list, int index1, int index2){ 121 | return list.get(index1-1).get(index2-1).equals("y"); 122 | } 123 | 124 | public static int getGraphCoreness(ArrayList> list){ 125 | ArrayList corenesses = getNodesCoreness(list); 126 | return Collections.max(corenesses); 127 | } 128 | 129 | public static int getNodeCoreness(ArrayList> list, int index){ 130 | ArrayList corenesses = getNodesCoreness(list); 131 | return corenesses.get(index-1); 132 | } 133 | 134 | public static int getMaxCorenessNodeNumber(ArrayList> list){ 135 | ArrayList corenesses = getNodesCoreness(list); 136 | int maxCoreness = Collections.max(corenesses); 137 | for(int i =0; i getNodesCoreness(ArrayList> list){ 147 | ArrayList corenesses = new ArrayList(); 148 | 149 | for(int i =0; i> listClone = CommonUtils.cloneMyArray(list); 155 | 156 | boolean isMark ; 157 | for(int k = 0; k <= maxDegree; k++){ 158 | ArrayList degrees = GraphUtils.getAllNodesDegree(listClone); 159 | isMark = false; 160 | for(int i = 0; i> list){ 179 | ArrayList degrees = GraphUtils.getAllNodesDegree(list); 180 | return Collections.max(degrees); 181 | } 182 | 183 | public static void markRemove(ArrayList> list, int index){ 184 | Collections.fill(list.get(index-1), "x"); 185 | 186 | for(int i =0; i> list){ 192 | int sumOfPath = 0; 193 | int numberOfPah = 0; 194 | for(int i =0; i paths = GraphUtils.widthSearch(list, i+1); 196 | for(int j = i+1; j0){ 198 | sumOfPath+=paths.get(j); 199 | numberOfPah++; 200 | } 201 | 202 | } 203 | } 204 | if(numberOfPah==0) 205 | return 0; 206 | return 1.0*sumOfPath/numberOfPah; 207 | } 208 | 209 | public static ArrayList widthSearch(ArrayList> list, int start){ 210 | ArrayList paths = new ArrayList(); 211 | for(int i =0; i visited = new ArrayList(); 216 | Queue queue = new LinkedList(); 217 | 218 | visited.add(startNode.number); 219 | paths.set(startNode.number, startNode.level); 220 | queue.offer(startNode); 221 | while(!queue.isEmpty()){ 222 | Node currNode = queue.poll(); 223 | for(int i=0; i> list){ 237 | ArrayList paths = GraphUtils.widthSearch(list, 1); 238 | Iterator iterator = paths.iterator(); 239 | while(iterator.hasNext()){ 240 | if(iterator.next() == -1) 241 | return false; 242 | } 243 | return true; 244 | } 245 | 246 | public static boolean isRemoved(ArrayList> list, int index){ 247 | return list.get(index-1).get(index-1).equals("x"); 248 | } 249 | 250 | public static boolean isAllRemoved(ArrayList> list){ 251 | for(int i =0; i getSubgraph(ArrayList> list){ 259 | int firstNodeNumber = 1; 260 | for(int i=0; i visited = new ArrayList(); 268 | Queue queue = new LinkedList(); 269 | 270 | visited.add(firstNodeNumber+1); 271 | queue.offer(firstNodeNumber+1); 272 | while(!queue.isEmpty()){ 273 | Integer currNodeNum = queue.poll(); 274 | for(int i=0; i> getSubgraphs(ArrayList> list){ 285 | ArrayList> subgraphs = new ArrayList>(); 286 | ArrayList> listclone = CommonUtils.cloneMyArray(list); 287 | while(!isAllRemoved(listclone)){ 288 | ArrayList subgraph = GraphUtils.getSubgraph(listclone); 289 | Iterator iterator = subgraph.iterator(); 290 | while(iterator.hasNext()){ 291 | int nodeNum = iterator.next(); 292 | GraphUtils.markRemove(listclone, nodeNum); 293 | } 294 | subgraphs.add(subgraph); 295 | } 296 | return subgraphs; 297 | } 298 | 299 | public static int getConnectedBranchNumber(ArrayList> list){ 300 | ArrayList> subgraphs = GraphUtils.getSubgraphs(list); 301 | return subgraphs.size(); 302 | } 303 | 304 | public static int sizeOfLargestSubgraph(ArrayList> list){ 305 | ArrayList> subgraphs = GraphUtils.getSubgraphs(list); 306 | int maxSize = 0; 307 | for(int i =0; i maxSize) 310 | maxSize = size; 311 | } 312 | return maxSize; 313 | } 314 | 315 | public static int getNumberOfNodes(ArrayList> list){ 316 | int numberOfNodes = 0; 317 | for(int i =0; i> list){ 325 | int numberOfEdges = 0; 326 | for(int i =0; i> list){ 338 | int maxDegree = GraphUtils.getMaxDegree(list); 339 | for(int i =0; i> list, 354 | int indexJ, int indexL){ 355 | ArrayList paths = GraphUtils.widthSearch(list, indexJ); 356 | return paths.get(indexL-1); 357 | } 358 | 359 | public static void randomAttack(ArrayList> list, int randomNode){ 360 | markRemove(list, randomNode); 361 | } 362 | 363 | public static void intentionalAttack(ArrayList> list, int index){ 364 | markRemove(list, index); 365 | } 366 | 367 | public static int getMaxNodeBetweennessNodeNumber(ArrayList> list){ 368 | double maxNodeBetweenness = Integer.MIN_VALUE; 369 | int maxNodeBetweennessNodeNumber = 0; 370 | for(int i=0; i maxNodeBetweenness){ 375 | maxNodeBetweenness = nodeBetweenness; 376 | maxNodeBetweennessNodeNumber = i+1; 377 | } 378 | } 379 | } 380 | return maxNodeBetweennessNodeNumber; 381 | } 382 | 383 | public static double getNodeBetweenness(ArrayList> list, int nodeNum){ 384 | double nodeBetweenness = 0; 385 | for(int i=0; i> list, int nodeNum, 397 | int indexJ, int indexL){ 398 | int allExistingShortesPath = GraphUtils.getAllExistingShortestPath(list, indexJ, indexL); 399 | int allExistingShortesPathPassThroughNode = GraphUtils.getAllExistingShortestPathPassThroughNode(list, 400 | nodeNum, indexJ, indexL ); 401 | if(allExistingShortesPath == 0) return 0; 402 | return 1.0*allExistingShortesPathPassThroughNode/allExistingShortesPath; 403 | } 404 | 405 | public static int getAllExistingShortestPath(ArrayList> list, 406 | int indexJ, int indexL){ 407 | ArrayList> allShortestPaths = GraphUtils 408 | .findAllShortestPaths(list, indexJ, indexL); 409 | return allShortestPaths.size(); 410 | } 411 | 412 | public static int getAllExistingShortestPathPassThroughNode(ArrayList> list, 413 | int nodeNum,int indexJ, int indexL){ 414 | ArrayList> allShortestPaths = GraphUtils 415 | .findAllShortestPaths(list, indexJ, indexL); 416 | int count = 0; 417 | for(int i=0; i shortestPath = allShortestPaths.get(i); 419 | if(shortestPath.contains(nodeNum)) 420 | count++; 421 | } 422 | return count; 423 | } 424 | 425 | public static ArrayList> findAllShortestPaths(ArrayList> list, 426 | int indexJ, int indexL){ 427 | ArrayList> allShortestPaths = new ArrayList>(); 428 | 429 | ArrayList> allPaths = new ArrayList>(); 430 | Stack stack = new Stack(); 431 | stack.add(indexJ); 432 | GraphUtils.dfsStack(list, indexL, stack, allPaths); 433 | 434 | if(allPaths.isEmpty()) 435 | return allShortestPaths; 436 | 437 | 438 | int minLength = Integer.MAX_VALUE; 439 | 440 | for(int i=0; i> list, int goal, 457 | Stack stack,ArrayList> paths){ 458 | System.out.println("\nջԪ��:"); 459 | System.out.println(stack); 460 | 461 | if(stack.isEmpty()) 462 | return ; 463 | 464 | int peekValue = stack.peek(); 465 | 466 | if(peekValue == goal) 467 | return ; 468 | 469 | for(int i=0; i path = new ArrayList(); 480 | Iterator iterator = stack.iterator(); 481 | while(iterator.hasNext()){ 482 | path.add(iterator.next()); 483 | } 484 | path.add(goal); 485 | paths.add(path); 486 | continue; 487 | } 488 | 489 | stack.push(i+1); 490 | dfsStack(list, goal, stack, paths); 491 | } 492 | } 493 | stack.pop(); 494 | } 495 | 496 | } 497 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/randomtest/RandomAttackBottomPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.randomtest; 2 | 3 | import edu.hitsz.utils.CommonUtils; 4 | import edu.hitsz.utils.GraphUtils; 5 | import edu.hitsz.utils.JXLUtils; 6 | import edu.hitsz.view.MainFrame; 7 | import jxl.read.biff.BiffException; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | import java.io.IOException; 14 | import java.util.ArrayList; 15 | 16 | public class RandomAttackBottomPanel extends JPanel{ 17 | 18 | int attackNodeNumber; 19 | 20 | public static final int WIDTH = RandomAttackFrame.WIDTH; 21 | public static final int HEIGHT = 340; 22 | private JLabel jlbNodes = null; 23 | private JTextField jtfNodes = null; 24 | private JLabel jlbedges = null; 25 | private JTextField jtfEdges = null; 26 | 27 | private JLabel jlbClusBef = null; 28 | private JTextField jtfClusBef = null; 29 | private JLabel jlbConnBef = null; 30 | private JTextField jtfConnBef = null; 31 | private JLabel jlbDegBef = null; 32 | private JTextField jtfDegBef = null; 33 | private JLabel jlbPathBef = null; 34 | private JTextField jtfPathBef = null; 35 | private JLabel jlbSizeBef = null; 36 | private JTextField jtfSizeBef = null; 37 | private JButton jbtAttBefDeg = null; 38 | private JLabel jlbNodesBef = null; 39 | private JTextField jtfNodesBef = null; 40 | private JLabel jlbEdgesBef = null; 41 | private JTextField jtfEdgesBef = null; 42 | 43 | private JLabel jlbClusAft = null; 44 | private JTextField jtfClusAft = null; 45 | private JLabel jlbConnAft = null; 46 | private JTextField jtfConnAft = null; 47 | private JLabel jlbDegAft = null; 48 | private JTextField jtfDegAft = null; 49 | private JLabel jlbPathAft = null; 50 | private JTextField jtfPathAft = null; 51 | private JLabel jlbSizeAft = null; 52 | private JTextField jtfSizeAft = null; 53 | private JButton jbtAttAftDeg = null; 54 | private JLabel jlbNodesAft = null; 55 | private JTextField jtfNodesAft = null; 56 | private JLabel jlbEdgesAft = null; 57 | private JTextField jtfEdgesAft = null; 58 | 59 | private JButton jbtReady = null; 60 | private JButton jbtStart = null; 61 | private JButton jbtReset = null; 62 | 63 | 64 | public RandomAttackBottomPanel(){ 65 | 66 | setLayout(null); 67 | 68 | jlbNodes = new JLabel("剩余节点:"); 69 | jlbNodes.setFont(new Font("Times",1, 15)); 70 | jlbNodes.setBounds(20, 10, 80, 50); 71 | 72 | jtfNodes = new JTextField(); 73 | jtfNodes.setEditable(false); 74 | jtfNodes.setFont(new Font("Times",1,15)); 75 | jtfNodes.setBorder(null); 76 | jtfNodes.setBounds(100, 10, 20, 50); 77 | 78 | jlbedges = new JLabel("剩余边数:"); 79 | jlbedges.setFont(new Font("Times", 1, 15)); 80 | jlbedges.setBounds(140, 10, 80, 50); 81 | 82 | jtfEdges = new JTextField(); 83 | jtfEdges.setEditable(false); 84 | jtfEdges.setFont(new Font("Times",1,15)); 85 | jtfEdges.setBorder(null); 86 | jtfEdges.setBounds(220, 10, 40, 50); 87 | 88 | jlbClusBef = new JLabel("clustering coefficient:"); 89 | jlbClusBef.setFont(new Font("Times",1 , 15)); 90 | jlbClusBef.setBounds(350, 20, 200, 50); 91 | 92 | jtfClusBef = new JTextField(); 93 | jtfClusBef.setEditable(false); 94 | jtfClusBef.setFont(new Font("Times", 1, 15)); 95 | jtfClusBef.setBorder(null); 96 | jtfClusBef.setBounds(520, 20, 40, 50); 97 | 98 | jlbConnBef = new JLabel("连通分支数:"); 99 | jlbConnBef.setFont(new Font("Times",1,15)); 100 | jlbConnBef.setBounds(350, 60, 200, 50); 101 | 102 | jtfConnBef = new JTextField(); 103 | jtfConnBef.setEditable(false); 104 | jtfConnBef.setFont(new Font("Times",1 ,15)); 105 | jtfConnBef.setBorder(null); 106 | jtfConnBef.setBounds(520, 60, 40, 50); 107 | 108 | jlbDegBef = new JLabel("平均度数:"); 109 | jlbDegBef.setFont(new Font("Times", 1, 15)); 110 | jlbDegBef.setBounds(350, 100, 200, 50); 111 | 112 | jtfDegBef = new JTextField(); 113 | jtfDegBef.setEditable(false); 114 | jtfDegBef.setFont(new Font("Times", 1, 15)); 115 | jtfDegBef.setBorder(null); 116 | jtfDegBef.setBounds(520, 100, 40, 50); 117 | 118 | jlbPathBef = new JLabel("平均最短路径:"); 119 | jlbPathBef.setFont(new Font("Times", 1, 15)); 120 | jlbPathBef.setBounds(350, 140, 200, 50); 121 | 122 | jtfPathBef = new JTextField(); 123 | jtfPathBef.setEditable(false); 124 | jtfPathBef.setFont(new Font("Times", 1, 15)); 125 | jtfPathBef.setBorder(null); 126 | jtfPathBef.setBounds(520, 140, 40, 50); 127 | 128 | jlbSizeBef = new JLabel("子图最大节点数:"); 129 | jlbSizeBef.setFont(new Font("Times", 1, 15)); 130 | jlbSizeBef.setBounds(350, 180, 200, 50); 131 | 132 | jtfSizeBef = new JTextField(); 133 | jtfSizeBef.setEditable(false); 134 | jtfSizeBef.setFont(new Font("Times", 1, 15)); 135 | jtfSizeBef.setBorder(null); 136 | jtfSizeBef.setBounds(520, 180,40,50 ); 137 | 138 | jlbNodesBef = new JLabel("节点数:"); 139 | jlbNodesBef.setFont(new Font("Times", 1, 15)); 140 | jlbNodesBef.setBounds(620, 20, 200, 50); 141 | 142 | jtfNodesBef = new JTextField(); 143 | jtfNodesBef.setEditable(false); 144 | jtfNodesBef.setFont(new Font("Times", 1, 15)); 145 | jtfNodesBef.setBorder(null); 146 | jtfNodesBef.setBounds(790, 20, 40, 50); 147 | 148 | jlbEdgesBef = new JLabel("边 数:"); 149 | jlbEdgesBef.setFont(new Font("Times", 1, 15)); 150 | jlbEdgesBef.setBounds(620, 60, 200, 50); 151 | 152 | jtfEdgesBef = new JTextField(); 153 | jtfEdgesBef.setEditable(false); 154 | jtfEdgesBef.setFont(new Font("Times", 1, 15)); 155 | jtfEdgesBef.setBorder(null); 156 | jtfEdgesBef.setBounds(790, 60, 40, 50); 157 | 158 | 159 | jlbClusAft = new JLabel("clustering coefficient:"); 160 | jlbClusAft.setFont(new Font("Times", 1, 15)); 161 | jlbClusAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH, 20, 200, 50); 162 | 163 | jtfClusAft = new JTextField(); 164 | jtfClusAft.setEditable(false); 165 | jtfClusAft.setFont(new Font("Times", 1, 15)); 166 | jtfClusAft.setBorder(null); 167 | jtfClusAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170, 20, 40, 50); 168 | 169 | jlbConnAft = new JLabel("连通分支数:"); 170 | jlbConnAft.setFont(new Font("Times", 1, 15)); 171 | jlbConnAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH, 60, 200, 50); 172 | 173 | jtfConnAft = new JTextField(); 174 | jtfConnAft.setEditable(false); 175 | jtfConnAft.setFont(new Font("Times", 1, 15)); 176 | jtfConnAft.setBorder(null); 177 | jtfConnAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170, 60, 40, 50); 178 | 179 | jlbDegAft = new JLabel("平均度数:"); 180 | jlbDegAft.setFont(new Font("Times", 1, 15)); 181 | jlbDegAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH, 100, 200, 50); 182 | 183 | jtfDegAft = new JTextField(); 184 | jtfDegAft.setEditable(false); 185 | jtfDegAft.setFont(new Font("Times", 1, 15)); 186 | jtfDegAft.setBorder(null); 187 | jtfDegAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170, 100, 40, 50); 188 | 189 | jlbPathAft = new JLabel("平均最短路径:"); 190 | jlbPathAft.setFont(new Font("Times", 1, 15)); 191 | jlbPathAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH, 140, 200, 50); 192 | 193 | jtfPathAft = new JTextField(); 194 | jtfPathAft.setEditable(false); 195 | jtfPathAft.setFont(new Font("Times", 1, 15)); 196 | jtfPathAft.setBorder(null); 197 | jtfPathAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170, 140, 40, 50); 198 | 199 | jlbSizeAft = new JLabel("子图最大节点数:"); 200 | jlbSizeAft.setFont(new Font("Times", 1, 15)); 201 | jlbSizeAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH, 180, 200, 50); 202 | 203 | jtfSizeAft = new JTextField(); 204 | jtfSizeAft.setEditable(false); 205 | jtfSizeAft.setFont(new Font("Times", 1, 15)); 206 | jtfSizeAft.setBorder(null); 207 | jtfSizeAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170, 180, 40, 50); 208 | 209 | jlbNodesAft = new JLabel("节点数:"); 210 | jlbNodesAft.setFont(new Font("Times", 1, 15)); 211 | jlbNodesAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170+100, 20, 200, 50); 212 | 213 | jtfNodesAft = new JTextField(); 214 | jtfNodesAft.setEditable(false); 215 | jtfNodesAft.setFont(new Font("Times",1 , 15)); 216 | jtfNodesAft.setBorder(null); 217 | jtfNodesAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170+270, 20, 40, 50); 218 | 219 | jlbEdgesAft = new JLabel("边 数:"); 220 | jlbEdgesAft.setFont(new Font("Times", 1, 15)); 221 | jlbEdgesAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170+100, 60, 200, 50); 222 | 223 | jtfEdgesAft = new JTextField(); 224 | jtfEdgesAft.setEditable(false); 225 | jtfEdgesAft.setFont(new Font("Times", 1, 15)); 226 | jtfEdgesAft.setBorder(null); 227 | jtfEdgesAft.setBounds(350+RandomAttackGraphBefPanel.WIDTH+170+270, 60, 40, 50); 228 | 229 | jbtReady = new JButton("准备攻击"); 230 | jbtReady.setFont(new Font("Times", 1, 20)); 231 | jbtReady.setBounds(30, 120, 200, 30); 232 | 233 | jbtStart = new JButton("开始攻击"); 234 | jbtStart.setFont(new Font("Times", 1, 20)); 235 | jbtStart.setBounds(30, 170, 200, 30); 236 | 237 | jbtReset = new JButton("回到开始"); 238 | jbtReset.setFont(new Font("Times", 1, 20)); 239 | jbtReset.setBounds(30, 220, 200, 30); 240 | 241 | this.add(jlbNodes); 242 | this.add(jtfNodes); 243 | this.add(jlbedges); 244 | this.add(jtfEdges); 245 | this.add(jlbClusBef); 246 | this.add(jtfClusBef); 247 | this.add(jlbConnBef); 248 | this.add(jtfConnBef); 249 | this.add(jlbDegBef); 250 | this.add(jtfDegBef); 251 | this.add(jlbPathBef); 252 | this.add(jtfPathBef); 253 | this.add(jlbSizeBef); 254 | this.add(jtfSizeBef); 255 | // this.add(jbtAttBefDeg); 256 | this.add(jlbClusAft); 257 | this.add(jtfClusAft); 258 | this.add(jlbConnAft); 259 | this.add(jtfConnAft); 260 | this.add(jlbDegAft); 261 | this.add(jtfDegAft); 262 | this.add(jlbPathAft); 263 | this.add(jtfPathAft); 264 | this.add(jlbSizeAft); 265 | this.add(jtfSizeAft); 266 | // this.add(jbtAttAftDeg); 267 | this.add(jlbNodesBef); 268 | this.add(jtfNodesBef); 269 | this.add(jlbEdgesBef); 270 | this.add(jtfEdgesBef); 271 | this.add(jlbNodesAft); 272 | this.add(jtfNodesAft); 273 | this.add(jlbEdgesAft); 274 | this.add(jtfEdgesAft); 275 | this.add(jbtReady); 276 | this.add(jbtStart); 277 | this.add(jbtReset); 278 | 279 | repaint(); 280 | 281 | jbtReady.addActionListener(new ActionListener() { 282 | 283 | @Override 284 | public void actionPerformed(ActionEvent e) { 285 | // TODO Auto-generated method stub 286 | 287 | attackNodeNumber = (int)(Math.random()*55)+1; 288 | while(RandomAttackFrame.befAttDatas.get(attackNodeNumber-1).get(attackNodeNumber-1).equals("x")){ 289 | attackNodeNumber = (int)(Math.random()*55)+1; 290 | } 291 | 292 | int numberOfNodes = GraphUtils.getNumberOfNodes(RandomAttackFrame.befAttDatas); 293 | jtfNodes.setText(numberOfNodes+""); 294 | 295 | jtfNodesBef.setText(numberOfNodes+""); 296 | 297 | int numberOfEdges = GraphUtils.getNumberOfEdges(RandomAttackFrame.befAttDatas); 298 | jtfEdges.setText(numberOfEdges+""); 299 | 300 | jtfEdgesBef.setText(numberOfEdges+""); 301 | 302 | double clusteringCoefficient = GraphUtils 303 | .getAverageClusteringCoefficient(RandomAttackFrame.befAttDatas); 304 | jtfClusBef.setText(String.format("%.2f", clusteringCoefficient)); 305 | 306 | int connBranNums = GraphUtils 307 | .getConnectedBranchNumber(RandomAttackFrame.befAttDatas); 308 | jtfConnBef.setText(connBranNums+""); 309 | 310 | double aveDegree = GraphUtils 311 | .getAverageDegree(RandomAttackFrame.befAttDatas); 312 | jtfDegBef.setText(String.format("%.2f", aveDegree)); 313 | 314 | double avePath = GraphUtils 315 | .getAverageShortestPath(RandomAttackFrame.befAttDatas); 316 | jtfPathBef.setText(String.format("%.2f", avePath)); 317 | 318 | int maxSizeOfSubgraph = GraphUtils 319 | .sizeOfLargestSubgraph(RandomAttackFrame.befAttDatas); 320 | jtfSizeBef.setText(maxSizeOfSubgraph+""); 321 | 322 | RandomAttackFrame.befAttDatas = CommonUtils.cloneMyArray(RandomAttackFrame.aftAttDatas); 323 | 324 | RandomAttackFrame.randomAttackGraphPanelBef.isPaint = true; 325 | 326 | RandomAttackFrame.randomAttackGraphPanelBef.setDatas(RandomAttackFrame.befAttDatas); 327 | 328 | RandomAttackFrame.randomAttackGraphPanelBef.removedNode = attackNodeNumber; 329 | 330 | RandomAttackFrame.randomAttackGraphPanelBef.repaint(); 331 | 332 | RandomAttackFrame.randomAttackGraphPanelAft.isPaint = false; 333 | 334 | RandomAttackFrame.randomAttackGraphPanelAft.repaint(); 335 | 336 | clearAftDatas(); 337 | 338 | 339 | } 340 | }); 341 | 342 | jbtStart.addActionListener(new ActionListener() { 343 | 344 | @Override 345 | public void actionPerformed(ActionEvent e) { 346 | // TODO Auto-generated method stub 347 | if( RandomAttackFrame.aftAttDatas.size()>0 && 348 | !GraphUtils.isRemoved(RandomAttackFrame.aftAttDatas, attackNodeNumber)){ 349 | 350 | GraphUtils.randomAttack(RandomAttackFrame.aftAttDatas,attackNodeNumber); 351 | 352 | RandomAttackTopPanel.addAttackNodesAndShow(attackNodeNumber); 353 | 354 | 355 | RandomAttackFrame.befAttDatas = CommonUtils.cloneMyArray(RandomAttackFrame.aftAttDatas); 356 | 357 | int numberOfNodes = GraphUtils.getNumberOfNodes(RandomAttackFrame.aftAttDatas); 358 | jtfNodes.setText(numberOfNodes+""); 359 | 360 | jtfNodesAft.setText(numberOfNodes+""); 361 | 362 | int numberOfEdges = GraphUtils.getNumberOfEdges(RandomAttackFrame.aftAttDatas); 363 | jtfEdges.setText(numberOfEdges+""); 364 | 365 | jtfEdgesAft.setText(numberOfEdges+""); 366 | 367 | double clusteringCoefficient = GraphUtils 368 | .getAverageClusteringCoefficient(RandomAttackFrame.aftAttDatas); 369 | jtfClusAft.setText(String.format("%.2f", clusteringCoefficient)); 370 | 371 | int connBranNums = GraphUtils 372 | .getConnectedBranchNumber(RandomAttackFrame.aftAttDatas); 373 | jtfConnAft.setText(connBranNums+""); 374 | 375 | double aveDegree = GraphUtils 376 | .getAverageDegree(RandomAttackFrame.aftAttDatas); 377 | jtfDegAft.setText(String.format("%.2f", aveDegree)); 378 | 379 | double avePath = GraphUtils 380 | .getAverageShortestPath(RandomAttackFrame.aftAttDatas); 381 | jtfPathAft.setText(String.format("%.2f", avePath)); 382 | 383 | int maxSizeOfSubgraph = GraphUtils 384 | .sizeOfLargestSubgraph(RandomAttackFrame.aftAttDatas); 385 | jtfSizeAft.setText(maxSizeOfSubgraph+""); 386 | 387 | RandomAttackFrame.randomAttackLeftSNPanel 388 | .addNodesAndShowSN(maxSizeOfSubgraph); 389 | 390 | RandomAttackFrame.randomAttackLeftLNPanel 391 | .addNodesAndShowLN(avePath); 392 | 393 | RandomAttackFrame.randomAttackGraphPanelAft.isPaint = true; 394 | 395 | RandomAttackFrame.randomAttackGraphPanelAft.setDatas(RandomAttackFrame.aftAttDatas); 396 | 397 | RandomAttackFrame.randomAttackGraphPanelAft.repaint(); 398 | 399 | } 400 | } 401 | }); 402 | 403 | jbtReset.addActionListener(new ActionListener() { 404 | 405 | @Override 406 | public void actionPerformed(ActionEvent e) { 407 | // TODO Auto-generated method stub 408 | RandomAttackFrame.testState = 0; 409 | RandomAttackFrame.reset(); 410 | clear(); 411 | RandomAttackTopPanel.clear(); 412 | 413 | RandomAttackFrame.randomAttackGraphPanelBef.clear(); 414 | RandomAttackFrame.randomAttackGraphPanelAft.clear(); 415 | 416 | RandomAttackFrame.randomAttackLeftLNPanel.clear(); 417 | RandomAttackFrame.randomAttackLeftSNPanel.clear(); 418 | } 419 | }); 420 | } 421 | 422 | protected void paintComponent(Graphics g){ 423 | super.paintComponent(g); 424 | g.drawLine(RandomAttackLeftLNPanel.WIDTH,0, 425 | RandomAttackLeftLNPanel.WIDTH, RandomAttackBottomPanel.HEIGHT); 426 | g.drawLine(0, 80, RandomAttackLeftLNPanel.WIDTH, 80); 427 | g.drawLine(RandomAttackLeftLNPanel.WIDTH+RandomAttackGraphBefPanel.WIDTH, 0, 428 | RandomAttackLeftLNPanel.WIDTH+RandomAttackGraphBefPanel.WIDTH, RandomAttackBottomPanel.HEIGHT); 429 | } 430 | 431 | private ArrayList> getDatas() { 432 | ArrayList> datas = null; 433 | try { 434 | datas = JXLUtils.readFile(MainFrame.filename, MainFrame.xlsNumbers); 435 | } catch (BiffException e1) { 436 | e1.printStackTrace(); 437 | } catch (IOException e1) { 438 | e1.printStackTrace(); 439 | } 440 | return datas; 441 | } 442 | 443 | public void clearBefDatas(){ 444 | jtfClusBef.setText(""); 445 | 446 | jtfConnBef.setText(""); 447 | 448 | jtfDegBef.setText(""); 449 | 450 | jtfPathBef.setText(""); 451 | 452 | jtfSizeBef.setText(""); 453 | 454 | jtfNodesBef.setText(""); 455 | 456 | jtfEdgesBef.setText(""); 457 | } 458 | 459 | public void clearAftDatas(){ 460 | jtfClusAft.setText(""); 461 | 462 | jtfConnAft.setText(""); 463 | 464 | jtfDegAft.setText(""); 465 | 466 | jtfPathAft.setText(""); 467 | 468 | jtfSizeAft.setText(""); 469 | 470 | jtfNodesAft.setText(""); 471 | 472 | jtfEdgesAft.setText(""); 473 | } 474 | 475 | public void clearLeftTopDatas(){ 476 | jtfNodes.setText(""); 477 | jtfEdges.setText(""); 478 | } 479 | 480 | public void clear(){ 481 | clearLeftTopDatas(); 482 | clearBefDatas(); 483 | clearAftDatas(); 484 | } 485 | } 486 | -------------------------------------------------------------------------------- /networks/src/main/java/edu/hitsz/view/robustness/intentionaltest/IntentionalAttackBottomPanel.java: -------------------------------------------------------------------------------- 1 | package edu.hitsz.view.robustness.intentionaltest; 2 | 3 | import edu.hitsz.utils.CommonUtils; 4 | import edu.hitsz.utils.GraphUtils; 5 | import edu.hitsz.utils.JXLUtils; 6 | import edu.hitsz.view.MainFrame; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.util.ArrayList; 13 | 14 | public class IntentionalAttackBottomPanel extends JPanel{ 15 | 16 | public static final int WIDTH = IntentionalAttackFrame.WIDTH; 17 | public static final int HEIGHT = 340; 18 | private JLabel jlbNodes = null; 19 | private JTextField jtfNodes = null; 20 | private JLabel jlbedges = null; 21 | private JTextField jtfEdges = null; 22 | 23 | private JLabel jlbClusBef = null; 24 | private JTextField jtfClusBef = null; 25 | private JLabel jlbConnBef = null; 26 | private JTextField jtfConnBef = null; 27 | private JLabel jlbDegBef = null; 28 | private JTextField jtfDegBef = null; 29 | private JLabel jlbPathBef = null; 30 | private JTextField jtfPathBef = null; 31 | private JLabel jlbSizeBef = null; 32 | private JTextField jtfSizeBef = null; 33 | private JButton jbtAttBefDeg = null; 34 | private JLabel jlbNodesBef = null; 35 | private JTextField jtfNodesBef = null; 36 | private JLabel jlbEdgesBef = null; 37 | private JTextField jtfEdgesBef = null; 38 | private JTextField input = null; 39 | private JLabel jlbOr = null; 40 | private JButton jbtMaxDeg = null; 41 | private JButton jbtMaxCore = null; 42 | private JButton jbtMaxNodeBet = null; 43 | 44 | private JLabel jlbClusAft = null; 45 | private JTextField jtfClusAft = null; 46 | private JLabel jlbConnAft = null; 47 | private JTextField jtfConnAft = null; 48 | private JLabel jlbDegAft = null; 49 | private JTextField jtfDegAft = null; 50 | private JLabel jlbPathAft = null; 51 | private JTextField jtfPathAft = null; 52 | private JLabel jlbSizeAft = null; 53 | private JTextField jtfSizeAft = null; 54 | private JButton jbtAttAftDeg = null; 55 | private JLabel jlbNodesAft = null; 56 | private JTextField jtfNodesAft = null; 57 | private JLabel jlbEdgesAft = null; 58 | private JTextField jtfEdgesAft = null; 59 | 60 | private JButton jbtReady = null; 61 | private JButton jbtStart = null; 62 | private JButton jbtReset = null; 63 | 64 | 65 | public IntentionalAttackBottomPanel(){ 66 | 67 | setLayout(null); 68 | 69 | jlbNodes = new JLabel("剩余节点:"); 70 | jlbNodes.setFont(new Font("Times",1, 15)); 71 | jlbNodes.setBounds(20, 10, 80, 50); 72 | 73 | jtfNodes = new JTextField(); 74 | jtfNodes.setEditable(false); 75 | jtfNodes.setFont(new Font("Times",1,15)); 76 | jtfNodes.setBorder(null); 77 | jtfNodes.setBounds(100, 10, 20, 50); 78 | 79 | jlbedges = new JLabel("剩余边数:"); 80 | jlbedges.setFont(new Font("Times", 1, 15)); 81 | jlbedges.setBounds(140, 10, 80, 50); 82 | 83 | jtfEdges = new JTextField(); 84 | jtfEdges.setEditable(false); 85 | jtfEdges.setFont(new Font("Times",1,15)); 86 | jtfEdges.setBorder(null); 87 | jtfEdges.setBounds(220, 10, 40, 50); 88 | 89 | jlbClusBef = new JLabel("clustering coefficient: "); 90 | jlbClusBef.setFont(new Font("Times",1 , 15)); 91 | jlbClusBef.setBounds(350, 20, 200, 50); 92 | 93 | jtfClusBef = new JTextField(); 94 | jtfClusBef.setEditable(false); 95 | jtfClusBef.setFont(new Font("Times", 1, 15)); 96 | jtfClusBef.setBorder(null); 97 | jtfClusBef.setBounds(520, 20, 40, 50); 98 | 99 | jlbConnBef = new JLabel("连通分支数: "); 100 | jlbConnBef.setFont(new Font("Times",1,15)); 101 | jlbConnBef.setBounds(350, 60, 200, 50); 102 | 103 | jtfConnBef = new JTextField(); 104 | jtfConnBef.setEditable(false); 105 | jtfConnBef.setFont(new Font("Times",1 ,15)); 106 | jtfConnBef.setBorder(null); 107 | jtfConnBef.setBounds(520, 60, 40, 50); 108 | 109 | jlbDegBef = new JLabel("平均度数: "); 110 | jlbDegBef.setFont(new Font("Times", 1, 15)); 111 | jlbDegBef.setBounds(350, 100, 200, 50); 112 | 113 | jtfDegBef = new JTextField(); 114 | jtfDegBef.setEditable(false); 115 | jtfDegBef.setFont(new Font("Times", 1, 15)); 116 | jtfDegBef.setBorder(null); 117 | jtfDegBef.setBounds(520, 100, 40, 50); 118 | 119 | jlbPathBef = new JLabel("平均最短路径: "); 120 | jlbPathBef.setFont(new Font("Times", 1, 15)); 121 | jlbPathBef.setBounds(350, 140, 200, 50); 122 | 123 | jtfPathBef = new JTextField(); 124 | jtfPathBef.setEditable(false); 125 | jtfPathBef.setFont(new Font("Times", 1, 15)); 126 | jtfPathBef.setBorder(null); 127 | jtfPathBef.setBounds(520, 140, 40, 50); 128 | 129 | jlbSizeBef = new JLabel("子图最大节点数:"); 130 | jlbSizeBef.setFont(new Font("Times", 1, 15)); 131 | jlbSizeBef.setBounds(350, 180, 200, 50); 132 | 133 | jtfSizeBef = new JTextField(); 134 | jtfSizeBef.setEditable(false); 135 | jtfSizeBef.setFont(new Font("Times", 1, 15)); 136 | jtfSizeBef.setBorder(null); 137 | jtfSizeBef.setBounds(520, 180,40,50 ); 138 | 139 | jlbNodesBef = new JLabel("节点数"); 140 | jlbNodesBef.setFont(new Font("Times", 1, 15)); 141 | jlbNodesBef.setBounds(620, 20, 200, 50); 142 | 143 | jtfNodesBef = new JTextField(); 144 | jtfNodesBef.setEditable(false); 145 | jtfNodesBef.setFont(new Font("Times", 1, 15)); 146 | jtfNodesBef.setBorder(null); 147 | jtfNodesBef.setBounds(790, 20, 40, 50); 148 | 149 | jlbEdgesBef = new JLabel("边 数:"); 150 | jlbEdgesBef.setFont(new Font("Times", 1, 15)); 151 | jlbEdgesBef.setBounds(620, 60, 200, 50); 152 | 153 | jtfEdgesBef = new JTextField(); 154 | jtfEdgesBef.setEditable(false); 155 | jtfEdgesBef.setFont(new Font("Times", 1, 15)); 156 | jtfEdgesBef.setBorder(null); 157 | jtfEdgesBef.setBounds(790, 60, 40, 50); 158 | 159 | jbtAttBefDeg = new JButton("显示度分布:"); 160 | jbtAttBefDeg.setFont(new Font("Times", 1, 15)); 161 | jbtAttBefDeg.setBounds(620, 180, 200, 40); 162 | 163 | jlbClusAft = new JLabel("clustering coefficient:"); 164 | jlbClusAft.setFont(new Font("Times", 1, 15)); 165 | jlbClusAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH, 20, 200, 50); 166 | 167 | jtfClusAft = new JTextField(); 168 | jtfClusAft.setEditable(false); 169 | jtfClusAft.setFont(new Font("Times", 1, 15)); 170 | jtfClusAft.setBorder(null); 171 | jtfClusAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170, 20, 40, 50); 172 | 173 | jlbConnAft = new JLabel("连通分支数: "); 174 | jlbConnAft.setFont(new Font("Times", 1, 15)); 175 | jlbConnAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH, 60, 200, 50); 176 | 177 | jtfConnAft = new JTextField(); 178 | jtfConnAft.setEditable(false); 179 | jtfConnAft.setFont(new Font("Times", 1, 15)); 180 | jtfConnAft.setBorder(null); 181 | jtfConnAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170, 60, 40, 50); 182 | 183 | jlbDegAft = new JLabel("平均度数: "); 184 | jlbDegAft.setFont(new Font("Times", 1, 15)); 185 | jlbDegAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH, 100, 200, 50); 186 | 187 | jtfDegAft = new JTextField(); 188 | jtfDegAft.setEditable(false); 189 | jtfDegAft.setFont(new Font("Times", 1, 15)); 190 | jtfDegAft.setBorder(null); 191 | jtfDegAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170, 100, 40, 50); 192 | 193 | jlbPathAft = new JLabel("平均最短路径: "); 194 | jlbPathAft.setFont(new Font("Times", 1, 15)); 195 | jlbPathAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH, 140, 200, 50); 196 | 197 | jtfPathAft = new JTextField(); 198 | jtfPathAft.setEditable(false); 199 | jtfPathAft.setFont(new Font("Times", 1, 15)); 200 | jtfPathAft.setBorder(null); 201 | jtfPathAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170, 140, 40, 50); 202 | 203 | jlbSizeAft = new JLabel("子图最大节点数:"); 204 | jlbSizeAft.setFont(new Font("Times", 1, 15)); 205 | jlbSizeAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH, 180, 200, 50); 206 | 207 | jtfSizeAft = new JTextField(); 208 | jtfSizeAft.setEditable(false); 209 | jtfSizeAft.setFont(new Font("Times", 1, 15)); 210 | jtfSizeAft.setBorder(null); 211 | jtfSizeAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170, 180, 40, 50); 212 | 213 | jlbNodesAft = new JLabel("节点数: "); 214 | jlbNodesAft.setFont(new Font("Times", 1, 15)); 215 | jlbNodesAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170+100, 20, 200, 50); 216 | 217 | jtfNodesAft = new JTextField(); 218 | jtfNodesAft.setEditable(false); 219 | jtfNodesAft.setFont(new Font("Times",1 , 15)); 220 | jtfNodesAft.setBorder(null); 221 | jtfNodesAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170+270, 20, 40, 50); 222 | 223 | jlbEdgesAft = new JLabel("边数: "); 224 | jlbEdgesAft.setFont(new Font("Times", 1, 15)); 225 | jlbEdgesAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170+100, 60, 200, 50); 226 | 227 | jtfEdgesAft = new JTextField(); 228 | jtfEdgesAft.setEditable(false); 229 | jtfEdgesAft.setFont(new Font("Times", 1, 15)); 230 | jtfEdgesAft.setBorder(null); 231 | jtfEdgesAft.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170+270, 60, 40, 50); 232 | 233 | jbtAttAftDeg = new JButton("????????"); 234 | jbtAttAftDeg.setFont(new Font("Times", 1, 15)); 235 | jbtAttAftDeg.setBounds(350+IntentionalAttackGraphBefPanel.WIDTH+170+100, 180, 200, 40); 236 | 237 | jbtReady = new JButton("准备攻击"); 238 | jbtReady.setFont(new Font("Times", 1, 20)); 239 | jbtReady.setBounds(30, 180, 200, 30); 240 | 241 | jbtStart = new JButton("开始攻击"); 242 | jbtStart.setFont(new Font("Times", 1, 20)); 243 | jbtStart.setBounds(30, 220, 200, 30); 244 | 245 | jbtReset = new JButton("回到开始"); 246 | jbtReset.setFont(new Font("Times", 1, 20)); 247 | jbtReset.setBounds(30, 260, 200, 30); 248 | 249 | jlbOr = new JLabel("输入或选择最大度数的节点:"); 250 | jlbOr.setFont(new Font("Times", 1, 15)); 251 | jlbOr.setBounds(10, 70, 200, 30); 252 | 253 | input = new JTextField(); 254 | input.setFont(new Font("Times", 1, 15)); 255 | input.setBounds(10, 110, 50, 30); 256 | 257 | jbtMaxDeg = new JButton("最大度"); 258 | jbtMaxDeg.setFont(new Font("Times", 1, 13)); 259 | jbtMaxDeg.setBounds(60, 110, 85, 30); 260 | 261 | jbtMaxCore = new JButton("最大coreness"); 262 | jbtMaxCore.setFont(new Font("Times",1, 13)); 263 | jbtMaxCore.setBounds(145, 110, 125, 30); 264 | 265 | jbtMaxNodeBet = new JButton("最大node-betweenness"); 266 | jbtMaxNodeBet.setFont(new Font("Times", 1, 13)); 267 | jbtMaxNodeBet.setBounds(60, 140, 210, 30); 268 | jbtMaxNodeBet.setEnabled(false); 269 | 270 | 271 | 272 | this.add(jlbNodes); 273 | this.add(jtfNodes); 274 | this.add(jlbedges); 275 | this.add(jtfEdges); 276 | this.add(jlbClusBef); 277 | this.add(jtfClusBef); 278 | this.add(jlbConnBef); 279 | this.add(jtfConnBef); 280 | this.add(jlbDegBef); 281 | this.add(jtfDegBef); 282 | this.add(jlbPathBef); 283 | this.add(jtfPathBef); 284 | this.add(jlbSizeBef); 285 | this.add(jtfSizeBef); 286 | this.add(jlbClusAft); 287 | this.add(jtfClusAft); 288 | this.add(jlbConnAft); 289 | this.add(jtfConnAft); 290 | this.add(jlbDegAft); 291 | this.add(jtfDegAft); 292 | this.add(jlbPathAft); 293 | this.add(jtfPathAft); 294 | this.add(jlbSizeAft); 295 | this.add(jtfSizeAft); 296 | this.add(jlbNodesBef); 297 | this.add(jtfNodesBef); 298 | this.add(jlbEdgesBef); 299 | this.add(jtfEdgesBef); 300 | this.add(jlbNodesAft); 301 | this.add(jtfNodesAft); 302 | this.add(jlbEdgesAft); 303 | this.add(jtfEdgesAft); 304 | this.add(jbtReady); 305 | this.add(jbtStart); 306 | this.add(jbtReset); 307 | this.add(jlbOr); 308 | this.add(input); 309 | this.add(jbtMaxDeg); 310 | this.add(jbtMaxCore); 311 | this.add(jbtMaxNodeBet); 312 | 313 | repaint(); 314 | 315 | jbtReady.addActionListener(new ActionListener() { 316 | 317 | @Override 318 | public void actionPerformed(ActionEvent e) { 319 | // TODO Auto-generated method stub 320 | if(IntentionalAttackFrame.testState == 0 && !input.getText().equals("")){ 321 | IntentionalAttackFrame.testState = 1; 322 | 323 | IntentionalAttackFrame.intentionalAttackGraphBefPanel 324 | .removedNode = Integer.parseInt(input.getText()); 325 | 326 | input.setEditable(false); 327 | 328 | int numberOfNodes = GraphUtils.getNumberOfNodes(IntentionalAttackFrame.befAttDatas); 329 | jtfNodes.setText(numberOfNodes+""); 330 | 331 | jtfNodesBef.setText(numberOfNodes+""); 332 | 333 | int numberOfEdges = GraphUtils.getNumberOfEdges(IntentionalAttackFrame.befAttDatas); 334 | jtfEdges.setText(numberOfEdges+""); 335 | 336 | jtfEdgesBef.setText(numberOfEdges+""); 337 | 338 | double clusteringCoefficient = GraphUtils 339 | .getAverageClusteringCoefficient(IntentionalAttackFrame.befAttDatas); 340 | jtfClusBef.setText(String.format("%.2f", clusteringCoefficient)); 341 | 342 | int connBranNums = GraphUtils 343 | .getConnectedBranchNumber(IntentionalAttackFrame.befAttDatas); 344 | jtfConnBef.setText(connBranNums+""); 345 | 346 | double aveDegree = GraphUtils 347 | .getAverageDegree(IntentionalAttackFrame.befAttDatas); 348 | jtfDegBef.setText(String.format("%.2f", aveDegree)); 349 | 350 | double avePath = GraphUtils 351 | .getAverageShortestPath(IntentionalAttackFrame.befAttDatas); 352 | jtfPathBef.setText(String.format("%.2f", avePath)); 353 | 354 | int maxSizeOfSubgraph = GraphUtils 355 | .sizeOfLargestSubgraph(IntentionalAttackFrame.befAttDatas); 356 | jtfSizeBef.setText(maxSizeOfSubgraph+""); 357 | 358 | IntentionalAttackFrame.befAttDatas = CommonUtils.cloneMyArray(IntentionalAttackFrame.aftAttDatas); 359 | 360 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.isPaint = true; 361 | 362 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.setDatas(IntentionalAttackFrame.befAttDatas); 363 | 364 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.repaint(); 365 | 366 | IntentionalAttackFrame.intentionalAttackGraphAftPanel.isPaint = false; 367 | 368 | IntentionalAttackFrame.intentionalAttackGraphAftPanel.repaint(); 369 | 370 | clearAftDatas(); 371 | 372 | } 373 | } 374 | }); 375 | 376 | jbtStart.addActionListener(new ActionListener() { 377 | 378 | @Override 379 | public void actionPerformed(ActionEvent e) { 380 | // TODO Auto-generated method stub 381 | if(IntentionalAttackFrame.testState == 1 382 | && !GraphUtils.isRemoved(IntentionalAttackFrame.aftAttDatas, 383 | Integer.parseInt(input.getText()))){ 384 | IntentionalAttackFrame.testState = 0; 385 | 386 | GraphUtils.intentionalAttack(IntentionalAttackFrame.aftAttDatas, 387 | Integer.parseInt(input.getText())); 388 | 389 | input.setEditable(true); 390 | 391 | IntentionalAttackFrame.befAttDatas = CommonUtils.cloneMyArray(IntentionalAttackFrame.aftAttDatas); 392 | IntentionalAttackTopPanel.addAttackNodesAndShow(Integer.parseInt(input.getText())); 393 | 394 | int numberOfNodes = GraphUtils.getNumberOfNodes(IntentionalAttackFrame.aftAttDatas); 395 | jtfNodes.setText(numberOfNodes+""); 396 | 397 | jtfNodesAft.setText(numberOfNodes+""); 398 | 399 | int numberOfEdges = GraphUtils.getNumberOfEdges(IntentionalAttackFrame.aftAttDatas); 400 | jtfEdges.setText(numberOfEdges+""); 401 | 402 | jtfEdgesAft.setText(numberOfEdges+""); 403 | 404 | double clusteringCoefficient = GraphUtils 405 | .getAverageClusteringCoefficient(IntentionalAttackFrame.aftAttDatas); 406 | jtfClusAft.setText(String.format("%.2f", clusteringCoefficient)); 407 | 408 | int connBranNums = GraphUtils 409 | .getConnectedBranchNumber(IntentionalAttackFrame.aftAttDatas); 410 | jtfConnAft.setText(connBranNums+""); 411 | 412 | double aveDegree = GraphUtils 413 | .getAverageDegree(IntentionalAttackFrame.aftAttDatas); 414 | jtfDegAft.setText(String.format("%.2f", aveDegree)); 415 | 416 | double avePath = GraphUtils 417 | .getAverageShortestPath(IntentionalAttackFrame.aftAttDatas); 418 | jtfPathAft.setText(String.format("%.2f", avePath)); 419 | 420 | int maxSizeOfSubgraph = GraphUtils 421 | .sizeOfLargestSubgraph(IntentionalAttackFrame.aftAttDatas); 422 | jtfSizeAft.setText(maxSizeOfSubgraph+""); 423 | 424 | 425 | 426 | IntentionalAttackFrame.intentionalAttackLeftSNPanel 427 | .addNodesAndShowSN(maxSizeOfSubgraph); 428 | 429 | IntentionalAttackFrame.intentionalAttackLeftLNPanel 430 | .addNodesAndShowLN(avePath); 431 | 432 | IntentionalAttackFrame.intentionalAttackGraphAftPanel.isPaint = true; 433 | 434 | IntentionalAttackFrame.intentionalAttackGraphAftPanel.setDatas(IntentionalAttackFrame.aftAttDatas); 435 | 436 | IntentionalAttackFrame.intentionalAttackGraphAftPanel.repaint(); 437 | 438 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.repaint(); 439 | 440 | } 441 | } 442 | }); 443 | 444 | jbtReset.addActionListener(new ActionListener() { 445 | 446 | @Override 447 | public void actionPerformed(ActionEvent e) { 448 | // TODO Auto-generated method stub 449 | IntentionalAttackFrame.testState = 0; 450 | IntentionalAttackFrame.reset(); 451 | clear(); 452 | IntentionalAttackTopPanel.clear(); 453 | 454 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.clear(); 455 | IntentionalAttackFrame.intentionalAttackGraphAftPanel.clear(); 456 | 457 | IntentionalAttackFrame.intentionalAttackLeftLNPanel.clear(); 458 | IntentionalAttackFrame.intentionalAttackLeftSNPanel.clear(); 459 | } 460 | }); 461 | 462 | jbtMaxDeg.addActionListener(new ActionListener() { 463 | 464 | @Override 465 | public void actionPerformed(ActionEvent e) { 466 | // if(input.isEditable()){ 467 | int maxDegreeNodeNumber = GraphUtils 468 | .getMaxDegreeNodeNumber(IntentionalAttackFrame.befAttDatas); 469 | input.setText(maxDegreeNodeNumber+""); 470 | 471 | IntentionalAttackFrame.intentionalAttackGraphBefPanel 472 | .removedNode = Integer.parseInt(input.getText()); 473 | 474 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.isPaint = true; 475 | 476 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.setDatas(IntentionalAttackFrame.befAttDatas); 477 | 478 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.repaint(); 479 | 480 | // IntentionalAttackFrame.intentionalAttackGraphAftPanel.clear(); 481 | // IntentionalAttackFrame.intentionalAttackGraphBefPanel 482 | // .removedNode = Integer.parseInt(input.getText()); 483 | // IntentionalAttackFrame.intentionalAttackGraphBefPanel.repaint(); 484 | // } 485 | } 486 | }); 487 | 488 | jbtMaxCore.addActionListener(new ActionListener() { 489 | 490 | @Override 491 | public void actionPerformed(ActionEvent e) { 492 | // TODO Auto-generated method stub 493 | int maxNodeCoreness = GraphUtils 494 | .getMaxCorenessNodeNumber(IntentionalAttackFrame.befAttDatas); 495 | input.setText(maxNodeCoreness+""); 496 | IntentionalAttackFrame.intentionalAttackGraphBefPanel 497 | .removedNode = Integer.parseInt(input.getText()); 498 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.isPaint = true; 499 | 500 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.setDatas(IntentionalAttackFrame.befAttDatas); 501 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.repaint(); 502 | } 503 | }); 504 | 505 | jbtMaxNodeBet.addActionListener(new ActionListener() { 506 | 507 | @Override 508 | public void actionPerformed(ActionEvent e) { 509 | // TODO Auto-generated method stub 510 | // int maxNodeBetweeness = GraphUtils 511 | // .getMaxNodeBetweennessNodeNumber(IntentionalAttackFrame.befAttDatas); 512 | double maxNodeBetweeness = GraphUtils 513 | .getNodeBetweenness(IntentionalAttackFrame.befAttDatas, 1); 514 | 515 | IntentionalAttackFrame.intentionalAttackGraphBefPanel 516 | .removedNode = Integer.parseInt(input.getText()); 517 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.isPaint = true; 518 | 519 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.setDatas(IntentionalAttackFrame.befAttDatas); 520 | IntentionalAttackFrame.intentionalAttackGraphBefPanel.repaint(); 521 | } 522 | }); 523 | } 524 | 525 | protected void paintComponent(Graphics g){ 526 | super.paintComponent(g); 527 | g.drawLine(IntentionalAttackLeftLNPanel.WIDTH,0, 528 | IntentionalAttackLeftLNPanel.WIDTH, IntentionalAttackBottomPanel.HEIGHT); 529 | g.drawLine(0, 60, IntentionalAttackLeftLNPanel.WIDTH, 60); 530 | g.drawLine(IntentionalAttackLeftLNPanel.WIDTH+IntentionalAttackGraphBefPanel.WIDTH, 0, 531 | IntentionalAttackLeftLNPanel.WIDTH+IntentionalAttackGraphBefPanel.WIDTH, IntentionalAttackBottomPanel.HEIGHT); 532 | } 533 | 534 | private ArrayList> getDatas() { 535 | ArrayList> datas = null; 536 | try { 537 | datas = JXLUtils.readFile(MainFrame.filename, MainFrame.xlsNumbers); 538 | } catch (Exception e1) { 539 | e1.printStackTrace(); 540 | } 541 | return datas; 542 | } 543 | 544 | public void clearBefDatas(){ 545 | jtfClusBef.setText(""); 546 | 547 | jtfConnBef.setText(""); 548 | 549 | jtfDegBef.setText(""); 550 | 551 | jtfPathBef.setText(""); 552 | 553 | jtfSizeBef.setText(""); 554 | 555 | jtfNodesBef.setText(""); 556 | 557 | jtfEdgesBef.setText(""); 558 | } 559 | 560 | public void clearAftDatas(){ 561 | jtfClusAft.setText(""); 562 | 563 | jtfConnAft.setText(""); 564 | 565 | jtfDegAft.setText(""); 566 | 567 | jtfPathAft.setText(""); 568 | 569 | jtfSizeAft.setText(""); 570 | 571 | jtfNodesAft.setText(""); 572 | 573 | jtfEdgesAft.setText(""); 574 | } 575 | 576 | public void clearLeftTopDatas(){ 577 | jtfNodes.setText(""); 578 | jtfEdges.setText(""); 579 | } 580 | 581 | public void clear(){ 582 | input.setText(""); 583 | input.setEditable(true); 584 | clearLeftTopDatas(); 585 | clearBefDatas(); 586 | clearAftDatas(); 587 | } 588 | } 589 | --------------------------------------------------------------------------------