Skip to content

Commit 20e4445

Browse files
Source code maintenance
*Add multi-dimensional route module *Add multi-dimensional route network generation algorithm *New multi-dimensional Dijkstra algorithm *New 2D Dijkstra algorithm
1 parent 7ff6747 commit 20e4445

36 files changed

+1599
-180
lines changed

KnowledgeDocument/Integrators and initiators-Chinese.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
```java
2525
import zhao.algorithmMagic.Integrator.Route2DDrawingIntegrator;
26-
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinatenet2D;
26+
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinateNet2D;
2727
import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateTwo;
2828
import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D;
2929

@@ -42,7 +42,7 @@ public class MAIN1 {
4242
DoubleConsanguinityRoute2D doubleConsanguinityRoute2D2 = DoubleConsanguinityRoute2D.parse("A -> C", A, C);
4343

4444
// 获取坐标网生成算法,这个对象就是实现了启动器接口的类,同时它本身还是一个算法
45-
ZhaoCoordinatenet2D zhaoCoordinatenet2D = ZhaoCoordinatenet2D.getInstance("Z");
45+
ZhaoCoordinateNet2D zhaoCoordinatenet2D = ZhaoCoordinateNet2D.getInstance("Z");
4646
zhaoCoordinatenet2D.addRoute(doubleConsanguinityRoute2D1);
4747
zhaoCoordinatenet2D.addRoute(doubleConsanguinityRoute2D2);
4848

KnowledgeDocument/Integrators and initiators.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ integrator
3434

3535
```java
3636
import zhao.algorithmMagic.Integrator.Route2DDrawingIntegrator;
37-
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinatenet2D;
37+
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinateNet2D;
3838
import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateTwo;
3939
import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D;
4040

@@ -53,7 +53,7 @@ public class MAIN1 {
5353
DoubleConsanguinityRoute2D doubleConsanguinityRoute2D2 = DoubleConsanguinityRoute2D.parse("A -> C", A, C);
5454

5555
// Get the coordinate network generation algorithm. This object is the class that implements the starter interface, and it is also an algorithm itself.法
56-
ZhaoCoordinatenet2D zhaoCoordinatenet2D = ZhaoCoordinatenet2D.getInstance("Z");
56+
ZhaoCoordinateNet2D zhaoCoordinatenet2D = ZhaoCoordinateNet2D.getInstance("Z");
5757
zhaoCoordinatenet2D.addRoute(doubleConsanguinityRoute2D1);
5858
zhaoCoordinatenet2D.addRoute(doubleConsanguinityRoute2D2);
5959

KnowledgeDocument/OperationAlgorithm-Chinese.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class MAIN1 {
9191
是我开发的一种新算法,主要用来自动解析坐标与坐标之间的联系,如果有可能的话,新增一个坐标就会生成一些有关的新联系,主页中使用这个算法进行了一个人与人之间的关系推断!
9292

9393
```java
94-
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinatenet2D;
94+
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinateNet2D;
9595
import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateTwo;
9696
import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D;
9797

@@ -105,7 +105,7 @@ public class MAIN1 {
105105
DoubleCoordinateTwo B = new DoubleCoordinateTwo(1, 3);
106106
DoubleCoordinateTwo C = new DoubleCoordinateTwo(2, 5);
107107
// 获取到坐标网生成算法
108-
ZhaoCoordinatenet2D l = ZhaoCoordinatenet2D.getInstance("L");
108+
ZhaoCoordinateNet2D l = ZhaoCoordinateNet2D.getInstance("L");
109109
// 将 A 主动认识 B的关系添加到网络中
110110
l.addRoute(DoubleConsanguinityRoute2D.parse("A -> B", A, B));
111111
// 将 A 主动认识 C的关系添加到网络中

KnowledgeDocument/OperationAlgorithm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ and coordinates. If possible, adding a new coordinate will generate some related
102102
in the homepage to conduct a personal and Relationship between people inferred!
103103

104104
```java
105-
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinatenet2D;
105+
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinateNet2D;
106106
import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateTwo;
107107
import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D;
108108

@@ -116,7 +116,7 @@ public class MAIN1 {
116116
DoubleCoordinateTwo B = new DoubleCoordinateTwo(1, 3);
117117
DoubleCoordinateTwo C = new DoubleCoordinateTwo(2, 5);
118118
// Get the coordinate network generation algorithm
119-
ZhaoCoordinatenet2D l = ZhaoCoordinatenet2D.getInstance("L");
119+
ZhaoCoordinateNet2D l = ZhaoCoordinateNet2D.getInstance("L");
120120
// Add the relationship that A actively knows B to the network
121121
l.addRoute(DoubleConsanguinityRoute2D.parse("A -> B", A, B));
122122
// Add the relationship that A actively knows C to the network

README-Chinese.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class MAIN1 {
6565
```
6666

6767
- 运行之后产生的关系网络图片
68+
6869
![image]((https://user-images.githubusercontent.com/113756063/196412140-8b81979d-ecc1-4774-9cbe-df8a89c19c1c.png)
6970

7071
### KnowledgeDocument
@@ -73,7 +74,7 @@ public class MAIN1 {
7374

7475
### src_code
7576

76-
ASMB的源码存放目录,在这里可以查看ASMBr的相关源码。当然这里是最新的源代码,你可以用它来编译,这样你就可以获得最新的版本。注意:最新版本往往不稳定,建议您使用已经发布很久的版本!
77+
ASMB的源码存放目录,在这里可以查看ASMB的相关源码。当然这里是最新的源代码,你可以用它来编译,这样你就可以获得最新的版本。注意:最新版本往往不稳定,建议您使用已经发布很久的版本!
7778

7879
### README-Chinese.md
7980

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class MAIN1 {
7979
```
8080

8181
- The relationship network picture generated after running
82+
8283
![image](https://user-images.githubusercontent.com/113756063/196412140-8b81979d-ecc1-4774-9cbe-df8a89c19c1c.png)
8384

8485
# directory structure
@@ -90,7 +91,7 @@ directly through the documents on the home page. There is no need to enter here
9091

9192
### src_code
9293

93-
The source code storage directory of ASMB, where you can view the relevant source code of ASMBr. Of course, here is the
94+
The source code storage directory of ASMB, where you can view the relevant source code of ASMB. Of course, here is the
9495
latest source code, which you can use to compile, so that you can obtain the latest version.
9596

9697
Note: The latest version is often unstable, so we recommend you to use the version that has been released for a long

src_code/src/main/java/zhao/algorithmMagic/Integrator/Route2DDrawingIntegrator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ public boolean run() {
171171
// 集成第二版接口
172172
run2(g);
173173
// 将图片对象输出到指定的路径下!
174-
ASIO.outImage(image, this.imageOutPath);
175-
logger.info("+--------------------------------------- << output Picture >> ---------------------------------------+");
174+
if (!ASIO.outImage(image, this.imageOutPath)) {
175+
logger.error("+ Error in image output!");
176+
} else {
177+
logger.info("+--------------------------------------- << output Picture >> ---------------------------------------+");
178+
}
176179
logger.info("+======================================= << " + this.IntegratorName + " >> stopped =============================================+");
177180
return true;
178181
}
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,9 @@
11
package zhao.algorithmMagic;
22

3-
import zhao.algorithmMagic.Integrator.Route2DDrawingIntegrator;
4-
import zhao.algorithmMagic.algorithm.generatingAlgorithm.ZhaoCoordinateNet2D;
5-
import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateTwo;
6-
import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D;
7-
83
/**
94
* 示例代码文件
105
*/
116
public class MAIN1 {
127
public static void main(String[] args) {
13-
// 构建人员坐标(二维)
14-
DoubleCoordinateTwo A = new DoubleCoordinateTwo(10, 10);
15-
DoubleCoordinateTwo B = new DoubleCoordinateTwo(-10, 4);
16-
DoubleCoordinateTwo C = new DoubleCoordinateTwo(1, 0);
17-
DoubleCoordinateTwo E = new DoubleCoordinateTwo(6, 1);
18-
DoubleCoordinateTwo Z = new DoubleCoordinateTwo(1, 21);
19-
20-
// 获取关系网络,该算法是我实现出来,用于推断人员关系网的,这里的名称您可以自定义,需要注意的是下面集成器的实例化需要您将该名称传进去
21-
ZhaoCoordinateNet2D zhaoCoordinateNet = ZhaoCoordinateNet2D.getInstance("Z");
22-
zhaoCoordinateNet.addRoute(DoubleConsanguinityRoute2D.parse("A -> B", A, B)); // Representing A takes the initiative to know B
23-
zhaoCoordinateNet.addRoute(DoubleConsanguinityRoute2D.parse("A -> C", A, C));
24-
zhaoCoordinateNet.addRoute(DoubleConsanguinityRoute2D.parse("E -> Z", E, Z));
25-
zhaoCoordinateNet.addRoute(DoubleConsanguinityRoute2D.parse("A -> Z", A, Z));
26-
zhaoCoordinateNet.addRoute(DoubleConsanguinityRoute2D.parse("B -> Z", B, Z));
27-
28-
// 使用2维路线绘制集成器,输出上面所有人员之间的关系网络图片
29-
Route2DDrawingIntegrator a = new Route2DDrawingIntegrator("A", "Z");
30-
// 设置图片输出路径
31-
a.setImageOutPath("D:\\out\\image.jpg")
32-
// 设置图片宽度
33-
.setImageWidth(1000)
34-
// 设置图片高度
35-
.setImageHeight(1000)
36-
// 设置离散阈值,用来放大微小的变化
37-
.setDiscreteThreshold(4)
38-
// 运行集成器!
39-
.run();
40-
41-
// 清理关系网络中的数据
42-
zhaoCoordinateNet.clear();
438
}
449
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package zhao.algorithmMagic.algorithm.differenceAlgorithm;
2+
3+
import org.apache.log4j.Logger;
4+
import zhao.algorithmMagic.algorithm.OperationAlgorithm;
5+
import zhao.algorithmMagic.algorithm.OperationAlgorithmManager;
6+
import zhao.algorithmMagic.exception.OperatorOperationException;
7+
import zhao.algorithmMagic.exception.TargetNotRealizedException;
8+
import zhao.algorithmMagic.operands.coordinate.Coordinate;
9+
import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates;
10+
import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates;
11+
import zhao.algorithmMagic.utils.ASClass;
12+
import zhao.algorithmMagic.utils.ASMath;
13+
14+
/**
15+
* Java类于 2022/10/19 11:38:33 创建
16+
* 布雷柯蒂斯距离(Bray Curtis Distance)主要用于生态学和环境科学,计算坐标之间的距离。该距离取值在[ 0 , 1 ] [0,1][0,1]之间,也可以用来计算样本之间的差异。
17+
* <p>
18+
* Bray Curtis Distance is mainly used in ecology and environmental science to calculate the distance between coordinates. The distance is between [ 0 , 1 ] [0,1][0,1] and can also be used to calculate the difference between samples.
19+
*
20+
* @author zhao
21+
*/
22+
public class BrayCurtisDistance<I extends IntegerCoordinates<I> & Coordinate<I>, D extends FloatingPointCoordinates<?>> implements DifferenceAlgorithm<D> {
23+
24+
protected final Logger logger;
25+
protected final String AlgorithmName;
26+
27+
protected BrayCurtisDistance() {
28+
this.AlgorithmName = "BrayCurtisDistance";
29+
this.logger = Logger.getLogger("BrayCurtisDistance");
30+
}
31+
32+
protected BrayCurtisDistance(String AlgorithmName) {
33+
this.logger = Logger.getLogger(AlgorithmName);
34+
this.AlgorithmName = AlgorithmName;
35+
}
36+
37+
/**
38+
* 获取到该算法的类对象。
39+
* <p>
40+
* Get the class object of the algorithm.
41+
*
42+
* @param Name 该算法的名称
43+
* @return 算法类对象
44+
* @throws TargetNotRealizedException 当您传入的算法名称对应的组件不能被成功提取的时候会抛出异常
45+
* <p>
46+
* An exception will be thrown when the component corresponding to the algorithm name you passed in cannot be successfully extracted
47+
*/
48+
public static <II extends IntegerCoordinates<II> & Coordinate<II>, DD extends FloatingPointCoordinates<?>> BrayCurtisDistance<II, DD> getInstance(String Name) {
49+
if (OperationAlgorithmManager.containsAlgorithmName(Name)) {
50+
OperationAlgorithm operationAlgorithm = OperationAlgorithmManager.getInstance().get(Name);
51+
if (operationAlgorithm instanceof BrayCurtisDistance<?, ?>) {
52+
return ASClass.transform(operationAlgorithm);
53+
} else {
54+
throw new TargetNotRealizedException("您提取的[" + Name + "]算法被找到了,但是它不属于ChebyshevDistance类型,请您为这个算法重新定义一个名称。\n" +
55+
"The [" + Name + "] algorithm you ParameterCombination has been found, but it does not belong to the ChebyshevDistance type. Please redefine a name for this algorithm.");
56+
}
57+
} else {
58+
BrayCurtisDistance<II, DD> brayCurtisDistance = new BrayCurtisDistance<>(Name);
59+
OperationAlgorithmManager.getInstance().register(brayCurtisDistance);
60+
return brayCurtisDistance;
61+
}
62+
}
63+
64+
/**
65+
* @return 该算法组件的名称,也是一个识别码,在获取算法的时候您可以通过该名称获取到算法对象
66+
* <p>
67+
* The name of the algorithm component is also an identification code. You can obtain the algorithm object through this name when obtaining the algorithm.
68+
*/
69+
@Override
70+
public String getAlgorithmName() {
71+
return this.AlgorithmName;
72+
}
73+
74+
/**
75+
* 算法模块的初始化方法,在这里您可以进行组件的初始化方法,当初始化成功之后,该算法就可以处于就绪的状态,一般这里就是将自己添加到算法管理类中
76+
* <p>
77+
* The initialization method of the algorithm module, here you can perform the initialization method of the component, when the initialization is successful, the algorithm can be in a ready state, generally here is to add yourself to the algorithm management class
78+
*
79+
* @return 初始化成功或失败。
80+
* <p>
81+
* Initialization succeeded or failed.
82+
*/
83+
@Override
84+
public boolean init() {
85+
if (!OperationAlgorithmManager.containsAlgorithmName(this.getAlgorithmName())) {
86+
OperationAlgorithmManager.getInstance().register(this);
87+
return true;
88+
} else {
89+
return false;
90+
}
91+
}
92+
93+
/**
94+
* 计算两个事物之间从差异系数百分比
95+
* <p>
96+
* Calculate the percentage difference from the coefficient of difference between two things
97+
*
98+
* @param value1 差异参数1
99+
* <p>
100+
* Difference parameter 1
101+
* @param value2 差异参数2
102+
* <p>
103+
* Difference parameter 2
104+
* @return 差异系数
105+
* <p>
106+
* Coefficient of Difference
107+
*/
108+
@Override
109+
public double getDifferenceRatio(D value1, D value2) {
110+
int numberOfDimensions1 = value1.getNumberOfDimensions();
111+
int numberOfDimensions2 = value2.getNumberOfDimensions();
112+
if (numberOfDimensions1 == numberOfDimensions2) {
113+
logger.info("ⁿ∑₁ |(DV1(n) - DV2(n))| / ⁿ∑₁ DV1(n) + ⁿ∑₁ DV2(n)");
114+
return getDifferenceRatio(value1.toArray(), value2.toArray());
115+
} else {
116+
throw new OperatorOperationException("BrayCurtisDistance算法运算出现错误,在进行两个坐标之间差异系数运算的时候,发现坐标的维度不同。\n" +
117+
"There is an error in the Bray Curtis Distance algorithm operation. When the difference coefficient between the two coordinates is calculated, it is found that the dimensions of the coordinates are different.\n" +
118+
"Number Of Dimensions => value1[" + numberOfDimensions1 + "] value2[" + numberOfDimensions2 + "]");
119+
}
120+
}
121+
122+
/**
123+
* 计算两个事物之间从差异系数百分比
124+
* <p>
125+
* Calculate the percentage difference from the coefficient of difference between two things
126+
*
127+
* @param value1 差异参数1
128+
* <p>
129+
* Difference parameter 1
130+
* @param value2 差异参数2
131+
* <p>
132+
* Difference parameter 2
133+
* @return 差异系数
134+
* <p>
135+
* Coefficient of Difference
136+
*/
137+
public double getDifferenceRatio(I value1, I value2) {
138+
int numberOfDimensions1 = value1.getNumberOfDimensions();
139+
int numberOfDimensions2 = value2.getNumberOfDimensions();
140+
if (numberOfDimensions1 == numberOfDimensions2) {
141+
logger.info("ⁿ∑₁ |(IV1(n) - IV2(n))| / ⁿ∑₁ IV1(n) + ⁿ∑₁ IV2(n)");
142+
return getDifferenceRatio(value1.toArray(), value2.toArray());
143+
} else {
144+
throw new OperatorOperationException("BrayCurtisDistance算法运算出现错误,在进行两个坐标之间差异系数运算的时候,发现坐标的维度不同。\n" +
145+
"There is an error in the Bray Curtis Distance algorithm operation. When the difference coefficient between the two coordinates is calculated, it is found that the dimensions of the coordinates are different.\n" +
146+
"Number Of Dimensions => value1[" + numberOfDimensions1 + "] value2[" + numberOfDimensions2 + "]");
147+
}
148+
}
149+
150+
/**
151+
* 计算两个数组之间的布雷柯蒂斯距离
152+
* <p>
153+
* Calculate the BrayCurtisDistance between two arrays
154+
*
155+
* @param doubles1 计算差异数组1
156+
* <p>
157+
* Calculate difference array 1
158+
* @param doubles2 计算差异数组2
159+
* <p>
160+
* Calculate difference array 2
161+
* @return Coefficient of Difference
162+
*/
163+
public double getDifferenceRatio(double[] doubles1, double[] doubles2) {
164+
double molecule = 0;
165+
double denominator = 0;
166+
for (int i = 0; i < doubles1.length; i++) {
167+
double v1 = doubles1[i];
168+
double v2 = doubles2[i];
169+
molecule += ASMath.absoluteValue(v1 - v2);
170+
denominator += v1 + v2;
171+
}
172+
logger.info("(ⁿ∑₁ |(V1(n) - V2(n))| / ⁿ∑₁ V1(n) + ⁿ∑₁ V2(n)) = (" + molecule + " / " + denominator + ")");
173+
return molecule >= denominator ? 1 : molecule / denominator;
174+
}
175+
176+
/**
177+
* 计算两个数组之间的布雷柯蒂斯距离
178+
* <p>
179+
* Calculate the BrayCurtisDistance between two arrays
180+
*
181+
* @param ints1 Calculate difference array 1
182+
* @param ints2 Calculate difference array 2
183+
* @return Coefficient of Difference
184+
*/
185+
public int getDifferenceRatio(int[] ints1, int[] ints2) {
186+
int molecule = 0;
187+
int denominator = 0;
188+
for (int i = 0; i < ints1.length; i++) {
189+
int v1 = ints1[i];
190+
int v2 = ints2[i];
191+
molecule += ASMath.absoluteValue(v1 - v2);
192+
denominator += v1 + v2;
193+
}
194+
logger.info("(ⁿ∑₁ |(V1(n) - V2(n))| / ⁿ∑₁ V1(n) + ⁿ∑₁ V2(n)) = (" + molecule + " / " + denominator + ")");
195+
return molecule >= denominator ? 1 : molecule / denominator;
196+
}
197+
}

src_code/src/main/java/zhao/algorithmMagic/algorithm/differenceAlgorithm/DifferenceAlgorithm.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
* 计算两个非向量等事物的差异的算法
77
* <p>
88
* Algorithms for computing the difference of two things that are not vectors, etc.
9+
*
10+
* @param <value> 需要计算的事务类型。
11+
* <p>
12+
* The type of transaction that needs to be calculated.
913
*/
10-
public interface DifferenceAlgorithm extends OperationAlgorithm {
14+
public interface DifferenceAlgorithm<value> extends OperationAlgorithm {
15+
16+
/**
17+
* 计算两个事物之间从差异系数百分比
18+
* <p>
19+
* Calculate the percentage difference from the coefficient of difference between two things
20+
*
21+
* @param value1 差异参数1
22+
* @param value2 差异参数2
23+
* @return 差异系数
24+
*/
25+
double getDifferenceRatio(value value1, value value2);
26+
1127
}

0 commit comments

Comments
 (0)