mirror of
https://github.com/tursom/TursomServer.git
synced 2025-03-14 03:40:06 +08:00
update maven publish
This commit is contained in:
parent
b69b6ba083
commit
0ae1b662c4
@ -1,5 +1,36 @@
|
||||
import cn.tursom.core.usingNanoTime
|
||||
import org.junit.Test
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.ParameterizedType
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
interface Type<T>
|
||||
|
||||
fun <T> f1(t: Type<T>) {
|
||||
}
|
||||
|
||||
fun f2(t: Type<Int>) {
|
||||
}
|
||||
|
||||
class TestType(
|
||||
val type: Type<Int>,
|
||||
)
|
||||
|
||||
fun getErasure(method: Method) {
|
||||
method.parameters.forEach { parameter ->
|
||||
val type = parameter.parameterizedType
|
||||
if (type !is ParameterizedType) return@forEach
|
||||
println(type.actualTypeArguments.asList())
|
||||
}
|
||||
}
|
||||
|
||||
fun getErasure(field: Field) {
|
||||
val type = field.genericType
|
||||
if (type !is ParameterizedType) return
|
||||
println(type.actualTypeArguments.asList())
|
||||
}
|
||||
|
||||
data class Flow(
|
||||
val source: Edge,
|
||||
@ -18,11 +49,13 @@ class Edge {
|
||||
}
|
||||
|
||||
private val sourceList: ArrayList<Flow> = ArrayList()
|
||||
private val flow: IntArray = IntArray(2)
|
||||
private val flowCache: IntArray = IntArray(2)
|
||||
private val flow = FloatArray(2)
|
||||
private val flowCache = FloatArray(2)
|
||||
//private val deltaRecord = FloatArray(2)
|
||||
//private var upCount = IntArray(2)
|
||||
|
||||
operator fun get(channel: FlowChannel) = flow[channel.index]
|
||||
operator fun set(channel: FlowChannel, value: Int) {
|
||||
operator fun set(channel: FlowChannel, value: Float) {
|
||||
flow[channel.index] = value
|
||||
}
|
||||
|
||||
@ -37,14 +70,22 @@ class Edge {
|
||||
}
|
||||
|
||||
fun calc() {
|
||||
flowCache.fill(0)
|
||||
flowCache.fill(0f)
|
||||
sourceList.forEach { (source, sourceFlowId, targetFlowId, fraction) ->
|
||||
flowCache[targetFlowId] += source.flow[sourceFlowId] shr fraction
|
||||
flowCache[targetFlowId] += source.flow[sourceFlowId] / (1 shl fraction)
|
||||
val d = abs(flowCache[targetFlowId] - flow[targetFlowId])
|
||||
//println("$d:${flow[targetFlowId]}")
|
||||
//if (flow[targetFlowId] != 0f && d >= flow[targetFlowId]) {
|
||||
// ++upCount[targetFlowId]
|
||||
//} else {
|
||||
// upCount[targetFlowId] = 0
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
fun finishCalc() {
|
||||
repeat(2) { index ->
|
||||
//deltaRecord[index] = flowCache[index] - flow[index]
|
||||
flow[index] = flowCache[index]
|
||||
}
|
||||
}
|
||||
@ -55,7 +96,8 @@ class Edge {
|
||||
|
||||
fun changed(): Boolean {
|
||||
repeat(2) { index ->
|
||||
if (flow[index] != flowCache[index]) {
|
||||
//if (upCount[index] > 10 || abs(flow[index] - flowCache[index]) > 1e-6) {
|
||||
if (flow[index] > 100 || abs(flow[index] - flowCache[index]) > 1e-6) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -64,8 +106,8 @@ class Edge {
|
||||
|
||||
fun clear() {
|
||||
repeat(2) {
|
||||
flow[it] = 0
|
||||
flowCache[it] = 0
|
||||
flow[it] = 0f
|
||||
flowCache[it] = 0f
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +117,7 @@ class Edge {
|
||||
}
|
||||
|
||||
class Graphic(
|
||||
var precision: Int = 8,
|
||||
//var precision: Int = 8,
|
||||
) : Iterable<Edge> {
|
||||
companion object {
|
||||
inline operator fun invoke(
|
||||
@ -98,7 +140,7 @@ class Graphic(
|
||||
fun getEdge(id: Int): Edge = edgeList[id]
|
||||
|
||||
fun calc() {
|
||||
edgeList[input][inputFlowChannel] = 1 shl precision
|
||||
edgeList[input][inputFlowChannel] = 1f
|
||||
edgeList.forEach { edge ->
|
||||
edge.calc()
|
||||
}
|
||||
@ -108,6 +150,7 @@ class Graphic(
|
||||
edgeList[input].finishCalc(inputFlowChannel)
|
||||
edgeList.forEach { edge ->
|
||||
if (edge.changed()) {
|
||||
//println("$edge changed")
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -126,7 +169,7 @@ class Graphic(
|
||||
}
|
||||
}
|
||||
|
||||
fun result(): List<Pair<Int, Int>> {
|
||||
fun result(): List<Pair<Float, Float>> {
|
||||
return edgeList.map { it[FlowChannel.A] to it[FlowChannel.B] }
|
||||
}
|
||||
|
||||
@ -134,14 +177,14 @@ class Graphic(
|
||||
|
||||
@Builder
|
||||
class GraphicBuilder {
|
||||
var precision: Int = 8
|
||||
//var precision: Int = 8
|
||||
val edgeMap = ArrayList<EdgeBuilder>()
|
||||
inline fun edge(builder: EdgeBuilder.() -> Unit) {
|
||||
edgeMap.add(EdgeBuilder(edgeMap.size).also(builder))
|
||||
}
|
||||
|
||||
fun build(): Graphic {
|
||||
val graphic = Graphic(precision)
|
||||
val graphic = Graphic()
|
||||
repeat(edgeMap.size) {
|
||||
graphic.addEdge(Edge())
|
||||
}
|
||||
@ -184,31 +227,55 @@ class Graphic(
|
||||
)
|
||||
}
|
||||
|
||||
class FlowExample {
|
||||
init {
|
||||
val graphic = getTestGraphic()
|
||||
|
||||
// 热车
|
||||
graphic.precision = 30
|
||||
repeat(10000) {
|
||||
graphic.clear()
|
||||
var changed = true
|
||||
while (changed) {
|
||||
graphic.calc()
|
||||
changed = graphic.changed()
|
||||
graphic.finishCalc()
|
||||
}
|
||||
fun Double.toFraction(): Pair<Int, Int> {
|
||||
var minI = 0
|
||||
var min = 1.0
|
||||
var minA = 0
|
||||
var i = 1
|
||||
for (n in 2..100) {
|
||||
i++
|
||||
val a = (this * n).roundToInt()
|
||||
val d = abs(1 - n * this / a)
|
||||
if (d < min) {
|
||||
min = d
|
||||
minA = a
|
||||
minI = i
|
||||
}
|
||||
}
|
||||
return minA to minI
|
||||
}
|
||||
|
||||
class FlowExample {
|
||||
fun <R> execute(func: Function<R>) {
|
||||
val type = func.javaClass.genericInterfaces[0] as ParameterizedType
|
||||
println(type)
|
||||
println(type.actualTypeArguments[0])
|
||||
}
|
||||
|
||||
fun <R> executeMatryoshka(func: Function<R>) = execute {
|
||||
func
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetErasure() {
|
||||
executeMatryoshka {
|
||||
}
|
||||
//getErasure(TestType::type.javaField!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToFraction() {
|
||||
println((17684.0 / 65534).toFraction())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
val graphic = getTestGraphic()
|
||||
graphic.precision = 8
|
||||
val graphic = getDeadTestGraphic()
|
||||
//graphic.precision = 13
|
||||
|
||||
var changed = true
|
||||
var step = 0
|
||||
while (changed) {
|
||||
while (changed && step < 1000) {
|
||||
step++
|
||||
graphic.calc()
|
||||
changed = graphic.changed()
|
||||
@ -216,6 +283,14 @@ class FlowExample {
|
||||
graphic.finishCalc()
|
||||
println(graphic.result())
|
||||
}
|
||||
//val sum = graphic.getEdge(0)[FlowChannel.B] + (7..11).sumOf {
|
||||
// graphic.getEdge(it)[FlowChannel.A].toDouble()
|
||||
//}
|
||||
//println(sum.toInt())
|
||||
//println((graphic.getEdge(0)[FlowChannel.B] / sum).toFraction())
|
||||
//(7..11).forEach {
|
||||
// println((graphic.getEdge(it)[FlowChannel.A] / sum).toFraction())
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,11 +300,23 @@ class FlowExample {
|
||||
fun testPerformance() {
|
||||
val graphic = getTestGraphic()
|
||||
|
||||
// 热车
|
||||
//graphic.precision = 16
|
||||
repeat(1000) {
|
||||
graphic.clear()
|
||||
var changed = true
|
||||
while (changed) {
|
||||
graphic.calc()
|
||||
changed = graphic.changed()
|
||||
graphic.finishCalc()
|
||||
}
|
||||
}
|
||||
|
||||
// 测试
|
||||
repeat(10000) {
|
||||
repeat(5) {
|
||||
intArrayOf(8, 12, 16, 20, 24, 28).forEach { precision ->
|
||||
graphic.clear()
|
||||
graphic.precision = precision
|
||||
//graphic.precision = precision
|
||||
|
||||
var step = 0
|
||||
var changed = true
|
||||
@ -247,6 +334,44 @@ class FlowExample {
|
||||
}
|
||||
}
|
||||
|
||||
fun getDeadTestGraphic() = Graphic {
|
||||
//0
|
||||
edge {
|
||||
}
|
||||
//1
|
||||
edge {
|
||||
flow(3, 1, 0)
|
||||
flow(5, 1, 1)
|
||||
}
|
||||
//2
|
||||
edge {
|
||||
flow(4, 1, 0)
|
||||
flow(5, 0, 1)
|
||||
flow(0, 0, 0, 1)
|
||||
}
|
||||
//3
|
||||
edge {
|
||||
flow(1, 1, 0)
|
||||
flow(6, 0, 1)
|
||||
flow(0, 0, 0, 1)
|
||||
}
|
||||
//4
|
||||
edge {
|
||||
flow(2, 1, 0)
|
||||
flow(6, 1, 1)
|
||||
}
|
||||
//5
|
||||
edge {
|
||||
flow(1, 0, 0)
|
||||
flow(2, 0, 1)
|
||||
}
|
||||
//6
|
||||
edge {
|
||||
flow(4, 0, 0)
|
||||
flow(3, 0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun getTestGraphic() = Graphic {
|
||||
// 0
|
||||
edge {
|
||||
@ -269,7 +394,7 @@ class FlowExample {
|
||||
}
|
||||
// 3
|
||||
edge {
|
||||
flow(1, 0, 0, 1)
|
||||
flow(2, 0, 0, 1)
|
||||
flow(8, 1, 0, 1)
|
||||
flow(9, 1, 1, 1)
|
||||
flow(4, 0, 1, 1)
|
||||
@ -286,7 +411,7 @@ class FlowExample {
|
||||
flow(6, 0, 0, 1)
|
||||
flow(11, 1, 0, 1)
|
||||
flow(4, 1, 1, 1)
|
||||
flow(0, 1, 1, 1)
|
||||
flow(10, 1, 1, 1)
|
||||
}
|
||||
// 6
|
||||
edge {
|
||||
@ -322,3 +447,4 @@ class FlowExample {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import java.text.SimpleDateFormat
|
||||
//import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
@ -21,7 +21,8 @@ try {
|
||||
}
|
||||
|
||||
group = "cn.tursom"
|
||||
version = SimpleDateFormat("yy.MM.dd-HH.mm").format(Date())
|
||||
//version = SimpleDateFormat("yy.MM.dd-HH.mm").format(Date())
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -105,19 +106,15 @@ publishing {
|
||||
}
|
||||
}
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
create<MavenPublication>("plugin") {
|
||||
groupId = project.group.toString()
|
||||
artifactId = project.name
|
||||
version = project.version.toString()
|
||||
|
||||
from(components["java"])
|
||||
try {
|
||||
artifact(tasks["sourcesJar"])
|
||||
artifact(tasks["kotlinSourcesJar"])
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
artifact(tasks["kotlinSourcesJar"])
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user