所有节点对的最短路径

发布一个k8s部署视频:https://edu.csdn.net/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.csdn.net/course/detail/27109

腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518

介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。

第三个视频发布:https://edu.csdn.net/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件
————————————————------------------------------------------------------------------------------------------------------------------

 

package com.data.struct;

import java.util.Random;

public class AllPairsShortestPath {
	private Node [][]graphic;
	public AllPairsShortestPath(int v,int e){
		graphic=new Node[v][v];
		for(int i=0;i<e;i++){
			int v1=new Random().nextInt(v);
			int v2=new Random().nextInt(v);
			Node node=new Node();
			//node.d=Integer.MAX_VALUE-1000;
			node.w=new Random().nextInt(v)+1;
			node.start=v1;
			node.end=v2;
			graphic[v1][v2]=node;
		}
		for(int i=0;i<v;i++){
			if(graphic[i][i]==null){
				Node node=new Node();
				//node.d=Integer.MAX_VALUE-1000;
				node.w=0;
				node.start=i;
				node.end=i;
				graphic[i][i]=node;
			}else{
				graphic[i][i].w=0;
			}
		}
		
	}
	public Node[][]extendShortestPaths(Node[][]l){
		Node[][]L=new Node[l.length][l.length];
		for(int i=0;i<L.length;i++){
			for(int j=0;j<L.length;j++){
				Node node=new Node();
				node.w=Integer.MAX_VALUE;
				L[i][j]=node;
				if(i==j){
					node.w=0;
				}else{
					for(int k=0;k<l.length;k++){
						if(l[i][k]!=null&&graphic[k][j]!=null){
							node.w=Math.min(node.w, l[i][k].w+graphic[k][j].w);
						}
					}
				}
				if(node.w==Integer.MAX_VALUE){
					L[i][j]=null;
				}
			}
		}
		return L;
	}
	
	public Node [][]fasterAllPairsShortestPath(){
		Node [][][] l=new Node[graphic.length][graphic.length][graphic.length];
		l[1]=graphic;
		int m=1;
		while(m<graphic.length-1){
			Node [][] a=extendShortestPaths(l[m]);
			System.out.println("a"+m*2+":");
			for(int i=0;i<a.length;i++){
				for(int j=0;j<a.length;j++){
					if(a[i][j]!=null){
						System.out.print(a[i][j].w+" ");
					}else{
						System.out.print(" "+" ");
					}
				}
				System.out.println();
			}
			for(int i=0;i<graphic.length;i++){
				for(int j=0;j<graphic.length;j++){
					Node node=new Node();
					for(int k=0;k<a.length;k++){
						node.start=i;
						node.end=j;
						if(a[i][j]!=null){
							node.w=a[i][j].w;
						}else{
							node.w=Integer.MAX_VALUE;
						}
						if(i==j){
							node.w=0;
						}else{
							if(a[i][k]!=null&&a[k][j]!=null){
								node.w=Math.min(node.w,a[i][k].w+a[k][j].w);
							}
						}
						
					}
					if(node.w==Integer.MAX_VALUE){
						l[2*m][i][j]=null;
					}else{
						l[2*m][i][j]=node;
					}
				}
			}
			System.out.println("l"+2*m+":");
			for(int i=0;i<l[2*m].length;i++){
				for(int j=0;j<l[2*m].length;j++){
					if(l[2*m][i][j]!=null){
						System.out.print(l[2*m][i][j].w+" ");
					}else{
						System.out.print(" "+" ");
					}
				}
				System.out.println();
			}
			m=2*m;
		}
		
		return l[m];
	}
	
	public void print(){
		System.out.println("origranal:");
		for(int i=0;i<graphic.length;i++){
			for(int j=0;j<graphic.length;j++){
				if(graphic[i][j]!=null){
					System.out.print(graphic[i][j].w+" ");
				}else{
					System.out.print(" "+" ");
				}
			}
			System.out.println();
		}
		
		Node [][] l=fasterAllPairsShortestPath();
		System.out.println("result:");
		for(int i=0;i<l.length;i++){
			for(int j=0;j<l.length;j++){
				if(l[i][j]!=null){
					System.out.print(l[i][j].w+" ");
				}else{
					System.out.print(" "+" ");
				}
			}
			System.out.println();
		}
	}
	
	
	private class Node{
		private int w;
		private int start;
		private int end;
	}

	public static void main(String[] args) {
		AllPairsShortestPath a=new AllPairsShortestPath(5,20);
		a.print();

	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值