[micro_ai] slow
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Re: [micro_ai] slow
I was quite sure thatCeltic_Minstrel wrote: ↑May 27th, 2018, 10:50 pm or useformula="moves > 0"
No. Like Ravana said,formula
cannot be used infilter_wml
.
moves
are inside filter_wml...Yeah I didn't mean that it's same.. I meant rather:Celtic_Minstrel wrote: ↑May 27th, 2018, 10:50 pm Also, "greater than 1" is not the same as "equal to 2 or 3".
a) would it work? (since filter_wml variables dont let me use coma separated list, or rather it doesnt work with range=2,3,4,5,6)
b) would it be same speed efficient if it worked with more simple and mathematically equaly written example... like:
Code: Select all
[filter]
formula="wml_vars.range = 2 or wml_vars.range = 3"
[/filter]
$this_unit
is also new to me.. I wonder if you know how speed efficient it is...? Because in viewtopic.php?f=10&t=46370&start=45#p626762 if I used $unit.side instead of $side_number inside filter it was about 10 times slower. Would it be different from $unit.side problem?so much useful information on filters... thank you very much Looks like I was quite very limited on my filters knowledge...Celtic_Minstrel wrote: ↑May 27th, 2018, 10:50 pm (I think wml_vars is undocumented, but it's basically the WFL way to access[variables
if I recall correctly.)
Could anyone give me a clue if putting into micro_ai code like this:
Code: Select all
[filter_location]
[filter]
id=$this_unit.id
[/filter]
radius=3
[/filter_location]
Code: Select all
[filter_location]
[filter]
side=$side_number
[/filter]
radius=3
[/filter_location]
$this_unit
not going to slow things down? And would it actually work?) Thanks in advance!Re: [micro_ai] slow
$this_unit performance was discussed few h ago in #wesnoth-dev, check logs for that, but I understand using $ in formula makes it 100 times slower.
id=$this_unit.id is always true, so same as no filter.
id=$this_unit.id is always true, so same as no filter.
Re: [micro_ai] slow
you mean using
$
in filters or using $
in formula=
? Or you mean just using formula=
?I might be understanding you I'm not sure...
I guess I need to try...
How does micro ai work? Does it store all units and then take each unit individually and trying to apply filter to it? Or does it use filter to store all units matching the filter and then is trying to apply filters locations individually? Or does it store all units matching the filter and then stores all locations matching the filter and then makes calculations? Is there a point to use $this_unit in MAI at all?
Re: [micro_ai] slow
In formula, $ prevents compiling the formula.
- Celtic_Minstrel
- Developer
- Posts: 2216
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [micro_ai] slow
Yes, moves is in filter_wml, but formula is not.enclave wrote: ↑May 28th, 2018, 2:49 amI was quite sure thatCeltic_Minstrel wrote: ↑May 27th, 2018, 10:50 pm or useformula="moves > 0"
No. Like Ravana said,formula
cannot be used infilter_wml
.moves
are inside filter_wml...
Formulas allow for a lot of [wiki=Wesnoth Formula Language]complicated things[/wiki]. For example, I believe you could get that sort of comma-separated list in a formula with
formula="wml_vars.range in [2, 3, 4, 5, 6]"
, or since they're consecutive numbers, the even shorter formula="wml_vars.range in 2 ~ 6"
should work, if I recall correctly.That linked page documents most of the functions you can use in a unit filter formula, but not all; some of the functions documented for FormulaAI also work (mainly ones that just deal with units or locations). Eventually I'll copy those over to the main WFL page.
Re: [micro_ai] slow
Celtic_Minstrel and Ravana already said most of it, so just a few additional things.
As a general rule though, do not use
Now, in the meantime I have talked on irc with Celtic_Minstrel and others and found out that I had misunderstood what he was suggesting. I also learned a couple things about filters that I didn’t know and gfgtdf fixed an inefficiency in SUF evaluation in the engine. Long story short, there's no need for separating evaluating the filter and eliminating units without moves any more. It can all be done quickly and efficiently in one step. So I'll do that and since this is just an internal change to improve efficiency with no API change, it will be in 1.14.3. That should give you the 40% speed improvement we've been talking about previously without you having to change anything.
this_unit
refers to the unit that is currently being looked at by the filter. So that line checks whether the id of the current unit is equal to the id of the current unit.As a general rule though, do not use
$this_unit
unless there is absolutely no other way, or in isolated cases when speed does not matter. It is super slow, just like [filter_wml]
. (I guess Ravana already said that too.)If you want to know the details, you should really have a look at the Goto MAI Lua code. To summarize though (see also my Points #6 and #7 from two days ago), it first finds all locations matching the SLF, then if finds all units matching the SUF (and then it does pathfinding for all valid combinations). As I said already, there’s a reason to do it that way and we will almost certainly not change that for the mainline version, but I also suggested that changing the order (do SUF first, then SLF) might give you the biggest time saving overall for your setting (if you adopted a local version of the AI).
Now, in the meantime I have talked on irc with Celtic_Minstrel and others and found out that I had misunderstood what he was suggesting. I also learned a couple things about filters that I didn’t know and gfgtdf fixed an inefficiency in SUF evaluation in the engine. Long story short, there's no need for separating evaluating the filter and eliminating units without moves any more. It can all be done quickly and efficiently in one step. So I'll do that and since this is just an internal change to improve efficiency with no API change, it will be in 1.14.3. That should give you the 40% speed improvement we've been talking about previously without you having to change anything.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: [micro_ai] slow
Thank you very much everyone I think I have enough tools now for a while.. so I'l get back here if I run in any kind of new trouble
By the way got an error for micro ai on 1.14.1
By the way got an error for micro ai on 1.14.1
Re: [micro_ai] slow
I just saw that you added that error report (I get notifications when a new post is made, but not when one is edited). I know what that message means, but there's no way of figuring out why it is happening without a test case. Do you still have the save from when you got this?
In other news:
In other news:
Be ready to be surprised then. We've implemented a number of changes to the filter evaluations for 1.14.3 (7be39c93, fb364cf2, 4b8870ed, 7727130e). With that, the lag time due to the AI evaluation at the end of the turn in the scenario you sent me is indeed down to 1 ms. Of course, the other 350 ms or so that have nothing to do with the MAI still remain.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: [micro_ai] slow
Unfortunately i dont have the save, I dont think so.. If i come across this again, I will save it and upload.mattsc wrote: ↑June 7th, 2018, 2:22 pm I just saw that you added that error report (I get notifications when a new post is made, but not when one is edited). I know what that message means, but there's no way of figuring out why it is happening without a test case. Do you still have the save from when you got this?
PS. I know about notifications, but that's what moderators want people like me to do... edit the posts instead of posting new.. so... ;(
That's great! Can't wait for 1.14.3 to be releasedmattsc wrote: ↑June 7th, 2018, 2:22 pm Be ready to be surprised then. We've implemented a number of changes to the filter evaluations for 1.14.3 (7be39c93, fb364cf2, 4b8870ed, 7727130e). With that, the lag time due to the AI evaluation at the end of the turn in the scenario you sent me is indeed down to 1 ms. Of course, the other 350 ms or so that have nothing to do with the MAI still remain.
By the way I wanted to ask, you mentioned that if I rebuild the ai as you advised it would only run on host, but what would happen if host leaves the game and new host is different player? Would everything still work without oos? If you are not sure, then tell me at least what you think? In future I might test it, or is it better worth to wait for 1.14.3 and not to play with custom candidate action? I mean if 1.14.3 is really such a huge difference maker, then I would rather wait and test the speed gain there.. and if it's not sufficient then custom candidate action still may help possibly?
Thanks for everything!
Re: [micro_ai] slow
Yeah, I know. This was meant as an explanation why I had not replied earlier, rather than a "complaint." There is some leeway with this though. You shouldn't make new posts with small incremental additions to previous thoughts, but a new bug report could get its own post so that it is noticed, as far as I know.
Actually, no, I won't guess. I really don't know and there's no point in me guessing because it wouldn't be worth anything since you'd just have to test it anyway. Maybe somebody else knows.enclave wrote: ↑June 8th, 2018, 12:33 am By the way I wanted to ask, you mentioned that if I rebuild the ai as you advised it would only run on host, but what would happen if host leaves the game and new host is different player? Would everything still work without oos? If you are not sure, then tell me at least what you think?
1.14.3 is supposed to be tagged this weekend, so I'd say wait and see how it works for you. You can then always still add a custom CA later (the changes to 1.14.3 only address a couple very specific problems, so there might be other things you want to do).enclave wrote: ↑June 8th, 2018, 12:33 am In future I might test it, or is it better worth to wait for 1.14.3 and not to play with custom candidate action? I mean if 1.14.3 is really such a huge difference maker, then I would rather wait and test the speed gain there.. and if it's not sufficient then custom candidate action still may help possibly?
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: [micro_ai] slow
The first impression was that it works like magic! I didn't evaluate it with numbers/speeds yet, but it is obvious to the human eye that it works much much quicker. If my further observation show the same successful improvement of speed then I'm very happy with the results, currently I don't see why I would try to change anything, since [micro_ai] now is really quick and works perfectly fine. I will later try to add more micro_ais and see if things start to slow down or not. Thank you very much for a huge improvement job!!!!!!!!!
Re: [micro_ai] slow
Hello again mattsc, it's been a while since my last question, but I have some new ones now
1) What happens to micro_ai when host leave the game? I remember you mentioned something that it's executed only on host machine, I don't remember for sure.. but in my own experience when host leaves I suspect that micro ai stops working.. is that true? What could be done to avoid it? What could be done to change it? (from add-on creator point of view, - what can I do about it?)
2) What happens to micro_ai after reload? I suspect that it stops working after reload of saved game.. I looked the debug inspect and all goals seems to be there.. but I have no proof that anything still works, I'm quite sure it doesn't... am I wrong/right? What could be done about it? If i put micro ai code into preload event would it solve it? would it create double code? (so if i put in preload then i need to delete the old micro_ai IDs that were there from turn 1/prestart/start event?)
no rush with answers.. I don't plan to do anything about it straight away.. I don't have time for changes.. but in not so far future (2 weeks maybe) I will so I need to know already, when you have time to answer. Thanks.
- Celtic_Minstrel
- Developer
- Posts: 2216
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [micro_ai] slow
I'm not mattsc, but I'm pretty sure a host leaving the game won't affect a micro_ai. Similarly, the micro_ai adds data into the saved game, so it should persist just fine through a reload. If it doesn't, that's probably a bug.
Re: [micro_ai] slow
Yeah, as Celtic_Minstrel says, neither of those should have an effect on a Micro AI. I did just do a quick test with the Goto MAI test scenario and it is definitely persistent there through reloading.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
-
- Posts: 2
- Joined: July 28th, 2018, 7:41 pm
Re: [micro_ai] slow
are you saying that you done the test and it works fine after reloading? thanks
which event did you have your micro_ai code?