åå ã¯ãåã
å ã«ä½ã£ã Gradle ããã¸ã§ã¯ãããIntelliJ ã使ã£ã¦ãããã°ããã¨ãããããã¾ããã
ä»åã¯ããã® Gradle ããã¸ã§ã¯ãã使ã£ã¦ãJGraphT ã¨ããã°ã©ãçè«ã®ã©ã¤ãã©ãªã Java ã§ä½¿ã£ã¦ã¿ã¾ãã
JGraphT ã§ç°¡åãªãµã³ãã«ãåããã¦ãGraphViz ã§å¯è¦åããã¨ããã¾ã§ããããã¨æãã¾ãã
JGraphT ã«ã¯ãPython ãã¤ã³ãã£ã³ã°ãããããã§ãã
ããã§ã¯ãã£ã¦ããã¾ãï¼
åèæç®
ã¯ããã«
ãJavaã§ãã¶ã¤ã³ãã¿ã¼ã³ãå¦ã¶ãã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
Javaã§ãã¶ã¤ã³ãã¿ã¼ã³ã®è¨äºä¸è¦§
JGraphT ã®å
¬å¼ãµã¤ãã¯ä»¥ä¸ã§ãã
jgrapht.org
ããã§ã¯ãã£ã¦ããã¾ãï¼
Gradleããã¸ã§ã¯ãã«JGraphTã追å ãã
Gradleããã¸ã§ã¯ãã§ã¯ãå¤é¨ã©ã¤ãã©ãªã使ãã¨ãã¯ããã®ä¾åé¢ä¿ãããã¸ã§ã¯ãã®ãã«ãã¹ã¯ãªããã«æ¸ãå¿
è¦ãããã¾ãã
ç¾å¨ã®ããã¸ã§ã¯ãã®ããªã¼ã表示ãã¦ããã¾ãã
$ tree
.
|-- app
| |-- build
| | |-- classes
| | | `-- java
| | | |-- main
| | | | `-- gradle
| | | | `-- demo
| | | | `-- App.class
| | | `-- test
| | | `-- gradle
| | | `-- demo
| | | `-- AppTest.class
| | |-- distributions
| | | |-- app
| | | | |-- bin
| | | | | |-- app
| | | | | `-- app.bat
| | | | `-- lib
| | | | |-- app.jar
| | | | |-- checker-qual-3.33.0.jar
| | | | |-- error_prone_annotations-2.18.0.jar
| | | | |-- failureaccess-1.0.1.jar
| | | | |-- guava-32.1.1-jre.jar
| | | | `-- jsr305-3.0.2.jar
| | | |-- app.tar
| | | `-- app.zip
| | |-- generated
| | | `-- sources
| | | |-- annotationProcessor
| | | | `-- java
| | | | |-- main
| | | | `-- test
| | | `-- headers
| | | `-- java
| | | |-- main
| | | `-- test
| | |-- libs
| | | `-- app.jar
| | |-- reports
| | | `-- tests
| | | `-- test
| | | |-- classes
| | | | `-- gradle.demo.AppTest.html
| | | |-- css
| | | | |-- base-style.css
| | | | `-- style.css
| | | |-- index.html
| | | |-- js
| | | | `-- report.js
| | | `-- packages
| | | `-- gradle.demo.html
| | |-- scripts
| | | |-- app
| | | `-- app.bat
| | |-- test-results
| | | `-- test
| | | |-- TEST-gradle.demo.AppTest.xml
| | | `-- binary
| | | |-- output.bin
| | | |-- output.bin.idx
| | | `-- results.bin
| | `-- tmp
| | |-- compileJava
| | | `-- previous-compilation-data.bin
| | |-- compileTestJava
| | | `-- previous-compilation-data.bin
| | |-- jar
| | | `-- MANIFEST.MF
| | `-- test
| |-- build.gradle.kts
| `-- src
| |-- main
| | |-- java
| | | `-- gradle
| | | `-- demo
| | | `-- App.java
| | `-- resources
| `-- test
| |-- java
| | `-- gradle
| | `-- demo
| | `-- AppTest.java
| `-- resources
|-- gradle
| `-- wrapper
| |-- gradle-wrapper.jar
| `-- gradle-wrapper.properties
|-- gradlew
|-- gradlew.bat
`-- settings.gradle.kts
54 directories, 36 files
éè¦ãªã®ã¯ã以ä¸ã®3ãã¡ã¤ã«ã§ãã
- settings.gradle.ktsï¼gradle-demoããã¸ã§ã¯ãã®è¨å®ãã¡ã¤ã«
- build.gradle.ktsï¼appããã¸ã§ã¯ãã®ãã«ãã¹ã¯ãªãã
- App.javaï¼appããã¸ã§ã¯ãã®Javaã½ã¼ã¹ãã¡ã¤ã«
appããã¸ã§ã¯ãã®ãã«ãã¹ã¯ãªããã«ãJGraphT ã®ä¾åé¢ä¿ã追å ãã¾ãã
å
¬å¼ãµã¤ãã«ããã«ããã¼ã«ã Maven ã®å ´åã®ä¾åé¢ä¿ã®è¿½å æ¹æ³ãæ¸ããã¦ãã¾ãããGradle ã®å ´åã¯æ¸ããã¦ãã¾ããã
ããããã¨ãã¯ã以ä¸ã«ã¢ã¯ã»ã¹ãã¾ãã
https://mvnrepository.com/
JGraphT ã§æ¤ç´¢ããã¨ãããã¤ãåºã¦ãã¾ããå¿
è¦ãªã®ã¯ãJGraphT Core ã¨ãå¯è¦åã®ããã® JGraphT I/O ã§ãã
ææ°ãã¼ã¸ã§ã³ã¯ã両æ¹ã¨ã 1.5.2 ã®ããã§ãã
JGraphT Core ã® 1.5.2 ã«ãGradleï¼Kotlinï¼ã®å ´åã®æ¸ãæ¹ãæ¸ããã¦ãã¾ãã
implementation("org.jgrapht:jgrapht-core:1.5.2")
JGraphT I/O ã®æ¹ã¯ã以ä¸ã§ãã
implementation("org.jgrapht:jgrapht-io:1.5.2")
ç¾å¨ã® appããã¸ã§ã¯ãã®ãã«ãã¹ã¯ãªããã® build.gradle.kts ã¯ä»¥ä¸ã§ãã
plugins {
application
}
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.9.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation("com.google.guava:guava:32.1.1-jre")
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
application {
mainClass.set("gradle.demo.App")
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
dependencies {}
ã«ãä¸ã®2ã¤ã追å ããã°ããã ãã§ãã
ããã§æºåã¯å®äºã§ãã
HelloJGraphTãå®è¡ãã
IntelliJ ãèµ·åãã¦ãgradle-demo ããã¸ã§ã¯ããéãã¾ãã
JGraphT Core 㨠JGraphT I/O ãèªã¿è¾¼ã¾ãã¦ãã¾ãã
JGraphT ã®å
¬å¼ãµã¤ãã« hello world ãããã¾ãï¼ä»¥ä¸ï¼ã
jgrapht.org
ãããã³ãã¼ãã¦ãApp.java ã¨åããã£ã¬ã¯ããªã«ãHelloJGraphT.java ãä½ã£ã¦è²¼ãä»ãã¾ãã
å
é ã«ããããã±ã¼ã¸åã ãå¤ãã¦ããã¾ãã
package gradle.demo;
ã¾ããappããã¸ã§ã¯ãã®ãã«ãã¹ã¯ãªããã® build.gradle.kts ã® application {}
ã以ä¸ã®ããã«ãã¾ãã
application {
mainClass.set("gradle.demo.HelloJGraphT")
}
ã§ã¯ãæ©éå®è¡ãã¦ã¿ã¾ãã
ã½ã¼ã¹ãå¤æ´ããã¨ããããã«ãã¹ã¯ãªãããå¤ããã¨ãã¯ãå·¦ã®ãµã¤ããã¼ã®ãã«ãã¢ã¤ã³ã³ãã¯ãªãã¯ãã¦ãåæã¿ãã®ãGradleããã¸ã§ã¯ãã®åãã¼ãããã¯ãªãã¯ããã¨åæ ããã¾ãã
ã¾ããå·¦ã®ããã¸ã§ã¯ãã®ããªã¼ã¯ãããã¡ã¤ã«âãã£ã¹ã¯ãããã¹ã¦åèªã¿è¾¼ã¿ããè¡ãã¨ãåæ ããã¾ãã
以ä¸ãå®è¡çµæã§ãã赤æ ã®ãããªçµæãåºåããã¦ããã°æåã ã¨æãã¾ãã
ä¸å¿ãããã°ã©ã ã®åºåçµæã ããè²¼ã£ã¦ããã¾ãã
-- toString output
([v1, v2, v3, v4], [{v1,v2}, {v2,v3}, {v3,v4}, {v4,v1}])
-- traverseHrefGraph output
http://www.jgrapht.org
http://www.wikipedia.org
http://www.google.com
-- renderHrefGraph output
strict digraph G {
www_google_com [ label="http://www.google.com" ];
www_wikipedia_org [ label="http://www.wikipedia.org" ];
www_jgrapht_org [ label="http://www.jgrapht.org" ];
www_jgrapht_org -> www_wikipedia_org;
www_google_com -> www_jgrapht_org;
www_google_com -> www_wikipedia_org;
www_wikipedia_org -> www_google_com;
}
HelloJGraphTããã¡ã¤ã«åºåã«å¤æ´ãã
å
ã»ã©ã®åºåçµæã®ä¸ã§ã-- renderHrefGraph output
ã®ã¨ããã¯ãGraphViz ã使ãã¨ã°ã©ããå¯è¦åã§ãã¾ãã
ã¾ããGraphViz ã®ã¤ã³ã¹ãã¼ã«ã§ãã
$ sudo apt install graphviz
ããã¹ããã¡ã¤ã«ã«å
ã»ã©ã®åºåçµæãè²¼ãä»ãã¾ãããã¡ã¤ã«å㯠HelloJGraphT.dot
ã¨ãã¾ãã
strict digraph G {
www_google_com [ label="http://www.google.com" ];
www_wikipedia_org [ label="http://www.wikipedia.org" ];
www_jgrapht_org [ label="http://www.jgrapht.org" ];
www_jgrapht_org -> www_wikipedia_org;
www_google_com -> www_jgrapht_org;
www_google_com -> www_wikipedia_org;
www_wikipedia_org -> www_google_com;
}
GraphViz ã§ç»åãã¡ã¤ã«ãåºåãã¾ãã
- -Tï¼åºåãã©ã¼ããããæå®ãã¾ããä»å㯠PNG ãæå®ãã¾ã
- å
¥åãã¡ã¤ã«ï¼ä»åã¯ãHelloJGraphT.dot ã§ã
- -oï¼åºåãã¡ã¤ã«åãæå®ãã¾ã
$ dot -Tpng HelloJGraphT.dot -oHelloJGraphT.png
åºåããã HelloJGraphT.png ã§ãã
ãã¼ãï¼é ç¹ï¼ã丸ã§å²ã¾ãã¦ãã¦ãã¨ãã¸ï¼è¾ºï¼ãç¢å°ï¼ä»åã¯æåã°ã©ãï¼ã§ç¤ºããã¦ãã¾ãã
ä»åã¯ãããã¾ã§ã«ãã¾ãã
ãããã«
ä»åã¯ãJGraphT ã使ã£ã¦ã¿ã¾ãããã°ã©ãã¯å¯è¦åãããã¨ã§ãã¨ã¦ãç解ãããããªãã¾ããã
次åã¯ãããå°ããJGraphT ã«ã¤ãã¦ä½¿ãæ¹ã調ã¹ã¦ããããã¨æãã¾ãã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã