Anylogic: printing the outputs to excel - java

I have some datasets which I want to print to excel after each run of simulation.
Dataset name: Arrival1,
Excel file name: ExcelOutputs,
The code that I wrote: excelOutputs.writeDataSet(this.Arrival1, "Tabelle1", 1, 1);
Data in dataset:
0 0
300 15
480 24
700 35
900 45
1,180 59
1,360 68
1,520 76
1,740 87
1,980 99
2,180 109
2,460 123
2,700 135
2,900 145
3,340 167
3,500 175
Data I get in the excel sheet:
0 0
340 17
580 29
700 35
900 45
1200 60
1420 71
1600 80
1800 90
2020 101
2200 110
2340 117
2520 126
2620 131
2820 141
3000 150
3220 161
3360 168
Totally different numbers and I don't know where they come from. There is no other dataset with these numbers and the excel sheet is initially empty.
Can someone please help me! Thank you in advance

Related

Way to read non-CSV file (including strings and integers) separated with varied spaces

I'm trying to read everything from this text file into my heap in java.
Achernar 537 272
Alcor 970 25
Aldebaran 737 356
Algol 900 325
Almagest 990 235
Alpha-Centauri 155 99
Altair 450 650
Antares 647 754
Arcturus 964 579
Belltrix 545 192
Beta-Cassiopia 378 525
Betelgeuse 412 377
Canopus 218 150
Capella 424 9
Delta-Cygnus 42 472
Deneb 218 8
Epsilon-Ceti 271 471
Epsilon-Cygnus 25 458
Fomalhaut 437 856
Gamma-Centauri 158 112
Gamma-Cygnus 56 471
Groombridge 996 904
Hyperion 656 127
Menkar 481 927
Metis 570 460
Microscopii 439 998
Mizar 41 130
Mu-Draconis 231 870
Organon 685 58
Pollux 565 9
Procyon 74 227
Regulus 373 106
Rigel 210 208
Siris 180 151
Sol 175 145
Theta-Persei 937 241
Vega 33 975
Vela 334 193
Zeeman 335 194
Zeta-Ptolemae 179 34
The regex that I typically use for CSV files (",[ ]*") doesn't work, I've been trying to modify it a little but I'm not sure where to go with it. Using the first line of the .txt as an example it should read Achernar as a String, 537 as a integer (x coordinate), and 272 as an integer (y coordinate).
I tried creating a String 'record', and splitting it into a String array 'tokens' with the using regex's like (""), (" "), and ("[ ]"), but when I try to read the the x coordinate after reading the string, I get an exception because the token array seems to be getting filled with spaces (instead of [Achernar, 537, 272] its something like [Achernar, , , , ... 537, 272].
I tried abandoning the token array and simply reading the inFile.hasNextLine() (which is what I'm using now) and there are no exceptions.. except it skips ever other entry in the text file because my parameter for the while loop is (inFile.hasNextLine()). I understand why this doesn't work, though, because its not just checking the nextLine, it checking if it exists and skipping it entire if it is there.
^^ My current code using that technique
while (inFile.hasNextLine()) {
entName = inFile.next();
entX = inFile.nextInt();
entY = inFile.nextInt();
Astro temp = new Astro(entName, entX, entY);
entDistance = temp.calculateDistance(x, y);
heap.enqueue(new Astro(entName, entX, entY, entDistance));
}

Default algo for RandomGenerator (L32X64MixRandom) generates the same number each time

The default algo for RandomGenerator ie. L32X64MixRandom as of JDK 18 (available since 17), generates the same number each time on individual invocations.
jshell> java.util.random.RandomGenerator.getDefault().nextInt(100,999)
$10 ==> 526
jshell> java.util.random.RandomGenerator.getDefault().nextInt(100,999)
$11 ==> 526
jshell> java.util.random.RandomGenerator.of("L32X64MixRandom").nextInt(100, 999)
$14 ==> 526
jshell> java.util.random.RandomGenerator.of("L32X64MixRandom").nextInt(100, 999)
$15 ==> 526
neither does javadoc sound any special caution:
Returns a pseudorandomly chosen int value between the specified origin (inclusive) and the specified bound (exclusive).
Implementation Requirements:
The default implementation checks that origin and bound are positive ints. Then invokes nextInt(), limiting the result to be greater that or equal origin and less than bound. If bound is a power of two then limiting is a simple masking operation. Otherwise, the result is re-calculated by invoking nextInt() until the result is greater than or equal origin and less than bound.
While other algos including legacy ones seem to have percieveable levels of randomness eg.
jshell> java.util.random.RandomGenerator.of("Random").nextInt(100,999)
$7 ==> 451
jshell> java.util.random.RandomGenerator.of("Random").nextInt(100,999)
$8 ==> 633
jshell> java.util.random.RandomGenerator.of("L64X128MixRandom").nextInt(100, 999)
$12 ==> 570
jshell> java.util.random.RandomGenerator.of("L64X128MixRandom").nextInt(100, 999)
$13 ==> 844
Is there a reason for this level of determinism with the default choice?
EDIT: behaviour wrt. streams is pretty similar, the initial value always seem to be the same
jshell> java.util.random.RandomGenerator.getDefault().ints(100,999).limit(5).toArray()
$22 ==> int[5] { 526, 860, 258, 558, 820 }
jshell> java.util.random.RandomGenerator.getDefault().ints(100,999).limit(5).toArray()
$23 ==> int[5] { 526, 866, 448, 654, 684 }
This is a bug listed at https://bugs.openjdk.java.net/browse/JDK-8282551
It is shown as fixed in Java 19, and there's a backport request to Java 17 and 18 (https://bugs.openjdk.java.net/browse/JDK-8284185 resolved 4/1/2022), but it's not clear when the backported fix will appear.
While this is a link-only answer, I believe it is appropriate because others will be encountering this bug and searching here.
For completeness, here's the code I used for my own test:
private static String[] algs =
{"L128X1024MixRandom",
"L128X128MixRandom",
"L128X256MixRandom",
"L32X64MixRandom",
"L64X1024MixRandom",
"L64X128MixRandom",
"L64X128StarStarRandom",
"L64X256MixRandom",
"Random",
"Xoroshiro128PlusPlus",
"Xoshiro256PlusPlus"};
public static void main(String[] args) throws Exception {
for (String alg : algs)
{
System.out.println("\nAlgorithm " + alg);
for (int i=0; i<5; i++)
{
RandomGenerator g = RandomGenerator.of(alg);
System.out.println(
g.ints(4,0,1000)
.boxed()
.map(x -> String.format("%5d",x))
.collect(Collectors.joining(" ")));
}
}
}
And the output from one run:
Algorithm L128X1024MixRandom
280 759 35 18
824 668 554 754
822 823 680 252
629 718 3 392
83 698 609 790
Algorithm L128X128MixRandom
973 765 392 815
495 164 744 418
621 117 836 271
787 819 463 825
150 473 159 777
Algorithm L128X256MixRandom
44 74 276 107
703 802 41 743
993 369 801 926
456 754 138 870
121 979 384 51
Algorithm L32X64MixRandom
152 372 238 19
152 334 300 942
152 739 206 818
152 284 200 628
152 835 259 588
Algorithm L64X1024MixRandom
782 247 982 974
316 507 860 386
571 563 166 646
888 553 779 342
121 750 764 68
Algorithm L64X128MixRandom
706 202 985 510
761 218 252 409
992 844 765 861
236 240 124 945
680 983 444 689
Algorithm L64X128StarStarRandom
619 40 879 489
599 622 396 225
76 359 104 31
205 687 741 488
141 732 509 172
Algorithm L64X256MixRandom
929 338 648 606
786 338 409 815
750 363 713 722
989 307 18 797
154 266 20 552
Algorithm Random
903 452 417 18
838 888 609 32
365 378 673 351
758 413 665 566
996 132 555 413
Algorithm Xoroshiro128PlusPlus
145 864 592 22
230 74 24 471
596 302 294 734
108 773 171 950
716 694 87 726
Algorithm Xoshiro256PlusPlus
563 528 572 853
619 722 534 10
87 306 594 525
149 430 243 836
578 938 802 539

Too many method references - using AppEngine SDK in Android Studio

I'm using App Engine Endpoints for my Android application. The problem is that I get the following error after using Endpoints and adding another SDK:
trouble writing output: Too many method references: 116924; max is 65536.
You may try using --multi-dex option.
References by package:
23 com.google.appengine.api
1540 com.google.appengine.api.appidentity
22 com.google.appengine.api.backends
1421 com.google.appengine.api.blobstore
4 com.google.appengine.api.blobstore.proto2api
795 com.google.appengine.api.capabilities
352 com.google.appengine.api.channel
2374 com.google.appengine.api.datastore
5231 com.google.appengine.api.files
2950 com.google.appengine.api.images
174 com.google.appengine.api.log
722 com.google.appengine.api.mail
4 com.google.appengine.api.mail.proto2api
10 com.google.appengine.api.mail.stdimpl
3711 com.google.appengine.api.memcache
48 com.google.appengine.api.memcache.stdimpl
2178 com.google.appengine.api.modules
38 com.google.appengine.api.oauth
1497 com.google.appengine.api.prospectivesearch
8 com.google.appengine.api.prospectivesearch.proto2api
27 com.google.appengine.api.quota
14 com.google.appengine.api.rdbms
606 com.google.appengine.api.search
79 com.google.appengine.api.search.checkers
381 com.google.appengine.api.search.query
3724 com.google.appengine.api.socket
4 com.google.appengine.api.socket.proto2api
5443 com.google.appengine.api.taskqueue
4 com.google.appengine.api.taskqueue.proto2api
966 com.google.appengine.api.urlfetch
43 com.google.appengine.api.users
44 com.google.appengine.api.utils
1463 com.google.appengine.api.xmpp
4 com.google.appengine.api.xmpp.proto2api
5480 com.google.appengine.repackaged.com.google.appengine.api.search
1243 com.google.appengine.repackaged.com.google.common.base
7 com.google.appengine.repackaged.com.google.common.base.internal
8524 com.google.appengine.repackaged.com.google.common.collect
103 com.google.appengine.repackaged.com.google.common.escape
379 com.google.appengine.repackaged.com.google.common.flags
642 com.google.appengine.repackaged.com.google.common.hash
1 com.google.appengine.repackaged.com.google.common.html
578 com.google.appengine.repackaged.com.google.common.io
103 com.google.appengine.repackaged.com.google.common.math
39 com.google.appengine.repackaged.com.google.common.net
2 com.google.appengine.repackaged.com.google.common.parameterset
556 com.google.appengine.repackaged.com.google.common.primitives
36 com.google.appengine.repackaged.com.google.common.util
753 com.google.appengine.repackaged.com.google.common.util.concurrent
5 com.google.appengine.repackaged.com.google.common.xml
290 com.google.appengine.repackaged.com.google.io.base
177 com.google.appengine.repackaged.com.google.io.base.shell
1348 com.google.appengine.repackaged.com.google.io.protocol
1752 com.google.appengine.repackaged.com.google.io.protocol.proto
8 com.google.appengine.repackaged.com.google.io.protocol.proto.proto2api
4 com.google.appengine.repackaged.com.google.io.protocol.proto2
24 com.google.appengine.repackaged.com.google.net.base
25 com.google.appengine.repackaged.com.google.net.util.error
10402 com.google.appengine.repackaged.com.google.protobuf
191 com.google.appengine.repackaged.com.google.protobuf.bridge
12 com.google.appengine.repackaged.com.google.protobuf.contrib.descriptor_pool
51 com.google.appengine.repackaged.com.google.protobuf.contrib.htmlform
384 com.google.appengine.repackaged.com.google.protobuf.downgraded
1540 com.google.appengine.repackaged.com.google.protos.gdata.proto2api
8 com.google.appengine.repackaged.com.google.protos.proto2.bridge
3173 com.google.appengine.repackaged.com.google.storage.onestore.v3.proto2api
407 com.google.appengine.repackaged.org.antlr.runtime
368 com.google.appengine.repackaged.org.antlr.runtime.debug
43 com.google.appengine.repackaged.org.antlr.runtime.misc
422 com.google.appengine.repackaged.org.antlr.runtime.tree
2015 com.google.appengine.repackaged.org.joda.time
268 com.google.appengine.repackaged.org.joda.time.base
858 com.google.appengine.repackaged.org.joda.time.chrono
120 com.google.appengine.repackaged.org.joda.time.convert
533 com.google.appengine.repackaged.org.joda.time.field
540 com.google.appengine.repackaged.org.joda.time.format
178 com.google.appengine.repackaged.org.joda.time.tz
26 com.google.appengine.spi
1521 com.google.appengine.tools.appstats
39 com.google.appengine.tools.compilation
6283 com.google.apphosting.api
1971 com.google.apphosting.api.logservice
4 com.google.apphosting.api.logservice.proto2api
739 com.google.apphosting.api.proto2api
1688 com.google.apphosting.api.search
8 com.google.apphosting.base
207 com.google.apphosting.client.datastoreservice.app
102 com.google.apphosting.client.datastoreservice.app.mobile
1782 com.google.apphosting.client.datastoreservice.mobile
2343 com.google.apphosting.client.datastoreservice.proto
51 com.google.apphosting.client.serviceapp
6714 com.google.apphosting.datastore
705 com.google.apphosting.utils.remoteapi
59 com.google.apphosting.utils.servlet
785 com.google.cloud.sql.jdbc
532 com.google.cloud.sql.jdbc.internal
5 com.google.httputil
1 com.google.inject
1 com.google.inject.util
1 com.google.net.base
39 com.google.net.rpc
6 com.google.net.rpc.impl
6 com.google.net.rpc3.client
1 com.google.net.rpc3.impl
3 com.google.net.rpc3.impl.compatibility
1 com.google.net.rpc3.impl.server
5 com.google.net.rpc3.server
1 com.google.net.ssl
6099 com.google.protos.cloud.sql
10 com.google.storage.onestore
2287 com.google.storage.onestore.v3
3 default
5 it.unimi.dsi.fastutil.ints
6 java.awt.datatransfer
10 java.beans
226 java.io
438 java.lang
13 java.lang.ref
36 java.lang.reflect
28 java.math
73 java.net
68 java.nio
7 java.nio.channels
16 java.nio.charset
16 java.security
40 java.sql
34 java.text
520 java.util
129 java.util.concurrent
26 java.util.concurrent.atomic
37 java.util.concurrent.locks
14 java.util.logging
18 java.util.regex
5 java.util.zip
163 javax.activation
13 javax.annotation.processing
49 javax.cache
1 javax.lang.model
19 javax.lang.model.element
4 javax.lang.model.type
4 javax.lang.model.util
405 javax.mail
59 javax.mail.event
502 javax.mail.internet
108 javax.mail.search
45 javax.mail.util
1 javax.net.ssl
6 javax.servlet
26 javax.servlet.http
2 javax.tools
3 org.antlr.stringtemplate
23 org.apache.geronimo.mail.handlers
190 org.apache.geronimo.mail.util
4 org.xml.sax
2 org.xml.sax.helpers
6 sun.misc
As you can see, com.google.appengine is taking most of the method references. How can I limit it?
you hit the 65k method limit, there are a few options you can do.
in your gradle file you can specify minifyEnabled = true and it will cut down unused resources and code.
you can also use the SDK build tools 21.1.X that supports multi dex file creation using the dependency
compile 'com.android.support:multidex:1.0.0'
along with adding in multiDexEnabled true to your gradle. more information can be found here

Converting between different keycodes

Im currently working on a little game. before you have started the game I have a JFrame where you can setup your controllers. To do this im using the java built-in keylistener and it works great.
The problem occurs when im starting the game and the settings youve made doesn't work.
The game uses the lwjgl api and slick2d api and the keycode for when im checking for buttonpresses is different from the keycodes built in keylistener.
http://slick.ninjacave.com/javadoc/constant-values.html#org.newdawn.slick.Input.KEY_DOWN
A list of the keycodes slick uses. As you can see its different from this list
http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
is there a way to convert between these two?
I tried adding a constant but as you probably can see it wont work.
I appreciate every answer :)
I made a little solution now. Very simple maybe not the most effiecent but it works. Took some time though
I made a little list that i use for conversion. Could be some bugs but they are pretty easy so fix.
backspace 8 14
space 32 57
tab 9 15
enter 13 28
enter2 10 28
shift 16 42
ctrl 17 29
alt 18 56
pause 19 197
caps 20 58
escape 27 1
pgup 33 201
pgdo 34 209
end 35 207
home 36 199
left 37 203
up 38 200
right 39 205
down 40 208
insert2 155 210
delete 127 211
0 48 11
1 49 2
2 50 3
3 51 4
4 5 5
5 53 6
6 54 7
7 55 8
8 56 9
9 57 10
A 65 30
B 66 48
C 67 46
D 68 32
E 69 18
F 70 33
G 71 34
H 72 35
I 73 23
J 74 36
K 75 37
L 76 38
M 77 50
N 78 49
O 79 24
P 80 25
Q 81 16
R 82 19
S 83 31
T 84 20
U 85 22
V 86 47
W 87 17
X 88 45
Y 89 21
Z 90 44
Å 16777413 27
Ä 16777412 40
Ö 16777430 41
LWK 91 219
RWK 92 220
WINDOWS 524 219
SELECT 93 221
NUMPAD0 96 82
NUMPAD1 97 79
NUMPAD2 98 80
NUMPAD3 99 81
NUMPAD4 100 75
NUMPAD5 101 76
NUMPAD6 102 77
NUMPAD7 103 71
NUMPAD8 104 72
NUMPAD9 105 73
MULTIPLY 106 55
ADD 107 78
SUBTRACT 109 74
DECIMAL 110 83
DIVIDE 111 181
F1 112 59
F2 113 60
F3 114 61
F4 115 62
F5 116 63
F6 117 64
F7 118 65
F8 119 66
F9 120 67
F10 121 68
F11 122 87
F12 123 88
F13 124 100
F14 125 101
F15 126 102
NUMLOCK 144 69
SCROLLOCK2 145 70
SEMICOLON 186 39
EQUALSIGN 187 13
COMMA 188 51
COMMA2 44 51
DASH 189 12
PERIOD 190 52
PERIOD2 46 52
FORWARDSLASH 191 53
GRAVE 192 41
OPENBRACKET 219 26
BACKSLASH 220 43
CLOSEBRAKET 221 27
SINGLEQUOTE 222 40
§ 16777383 43
LESS 153 -1
DEADACUTE 129 -1
PLUS 521 13
MINUS 45 12
DeadDiaeresis 135 144

Obtaining EVDEV Event Code from raw bytes?

In a previous question , I asked how to interpret the event bytes from /dev/input/mice. Realizing now that /dev/input/mice does NOT give me the information I need, as I am using a touchscreen using the stmpe-ts driver. It is setup under EVDEV node /dev/input/event2, and using a personal program I built, I can obtain the neccessary bytes from this file. My only problem is translating that into Event Codes. Using evtest, I get this output:
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "stmpe-ts"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 330 (BTN_TOUCH)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 2486
Min 0
Max 4095
Event code 1 (ABS_Y)
Value 1299
Min 0
Max 4095
Event code 24 (ABS_PRESSURE)
Value 0
Min 0
Max 255
Properties:
Testing ... (interrupt to exit)
I need those event codes, from the raw data obtained by reading directly from /dev/input/event2. This is as follows:
236 21 100 83 63 223 11 0 3 0 0 0 124 8 0 0 236 21 100 83 72 223 11 0 3 0 1 0 237 7
0 0 236 21 100 83 76 223 11 0 3 0 24 0 60 0 0 0 236 21 100 83 80 223 11 0 1 0 74
1 1 0 0 0 236 21 100 83 84 223 11 0 0 0 0 0 0 0 0 0 236 21 100 83 251 247 11 0 3 0 0 0
123 8 0 0 236 21 100 83 6 248 11 0 3 0 1 0 242 7 0 0 236 21 100 83 10 248 11 0 3 0 24
0 142 0 0 0 236 21 100 83 16 248 11 0 0 0 0 0 0 0 0 0 236 21 100 83 137 16 12 0 3 0 0
0 121 8 0 0 236 21 100 83 147 16 12 0 3 0 1 0 7 8 0 0 236 21 100 83 150 16 12 0 3 0 24
0 163 0 0 0 236 21 100 83 156 16 12 0 0 0 0 0 0 0 0 0
Is this even possible to do? If so, can someone help me out here? (Also, I've determined that a pattern occurs every 16 bytes or so, I've also determined that 236 and 237 are byte stating that the event is a touch event, 236 being touch without click, and 237 being touch with click)
The output of evdev nodes is a series of struct input_event, defined in linux/input.h.
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
So all you need to do is read into an array of those structs and then access each type/code as needed. Don't know how to do that in Java, but it's probably not that hard.
evtest is free software btw, so you can look at the code and see what it does.
Also look at libevdev, it's MIT license so you don't get 'tainted' by looking at it.
http://www.freedesktop.org/wiki/Software/libevdev/

Categories

Resources