Condor DAG file - parents with many children. Is it legal to have the parents of a child denoted on multiple lines instead of one? - directed-acyclic-graphs

Here's a simple tree of what I have:
A B
\ /
C
A and B are the parent processes and C can only run after A and B have finished.
Normally, the DAG file would look like so:
JOB A a.condor
JOB B b.condor
JOB C c.condor
PARENT A, B CHILD C
I was wondering if anyone knows if the following would also work:
JOB A a.condor
JOB B b.condor
JOB C c.condor
PARENT A CHILD C
PARENT B CHILD C
I've looked through the Condor DAG documentation, but it's not much help.
Thanks!

Yes, both of your examples are valid and equivalent. You can make as many PARENT/CHILD declarations as you want—even with the same node referenced in more than one declaration—and as long as there are no cycles, DAGMan will use them all.
Here is a support ticket with the Condor developers to clarify this point in the documentation.

The DAG parser is pretty stupid, so the line "PARENT A, B Child C" will cause a problem when DAGMan tries to find a node named "A,". i.e., you should drop the comma.

Related

Applescript - running handlers from a list

I'm trying out this code in applescript:
the first one works, the second doesn't
global theOpts
on saySomething()
--some code that it runs
end
set theOpts to {saySomething}
--the one that does
set t to theOpts's item 1
t()
--the one that doesn't
on runByIdx(idx)
set thefun to item 1 of theOpts
thefun()
end runByIdx
Is there a way I can get this to work?
What I want to do in summary is have a list of handlers that I can call by index rather than by name.
Don't do that. It's an undocumented behavior and known design flaw. Handlers aren't meant to be manipulated as objects, and it breaks the handler's bindings to the enclosing script.
The right way to do it is to wrap each handler in its own script object, and put those script objects in the list instead.
script Foo
on doIt()
say "this"
end doIt
end script
script Bar
on doIt()
say "that"
end doIt
end script
set opts to {Foo, Bar}
doIt() of item 1 of opts
Though you should also not underestimate the value of a simple if...else if... block:
if idx = 1 then
doThis()
else idx = 2 then
doThat()
else ...
Basically it depends on what problem you're trying to solve. But I'd lean towards the latter approach (i.e. KISS) unless it's a task that requires the extra flexibility, otherwise you're just adding unnecessary complexity and making work for yourself.
(FWIW, the AppleScript book I co-wrote a few years back has a chapter on working with script objects. The section on libraries doesn't cover the new library system in 10.9+, and the section on OOP has a corker of a technical error if you know where to look:p, but it's probably the best explanation of this subject you'll find so worth a look if you really want to know more.)
This way both work...
global theOpts
on saySomething()
return 1
end saySomething
set theOpts to {saySomething()}
--the one that does
set t to theOpts's item 1
--t
runByIdx(1)
on runByIdx(idx)
set thefun to item idx of theOpts
thefun
end runByIdx

Lua: Redirect extern function definitions to a specified table

I have one file "example.lua":
local function manipulate(something)
return string.rep(something, 3) -- repeats the given string
end
function apiFunction(somethingelse)
return manipulate(somethingelse)
end
and another files (main.lua) task is to "load"/"do" it:
loadAPI("example.lua", "externAPI") --< the part i need help with
externAPI.apiFunction("Test") --> should return TestTestTest
the thing that should happen is, that example.lua gets executed just like
dofile("example.lua")
but everything globally "defined" within example.lua (in this case the apiFunction) moves to the new generated global "externAPI" table and the rest (ie. manipulate) is hidden and only available from inside the example.lua file.
I've seen this bahaviour before in the minecraft mod "ComputerCraft" in which there is a function called "os.loadAPI("/somepath/sha-2") and it would define the definitions in the sha-2-chunk in the due to the name specified "sha-2"-table.
I've been searching for this sort of scoping/redirecting stuff for a while but there are no solutions putting the stuff into the new table.
I've been thinking of parsing the _G table after new indexes and move those to the new table but I'm sure there are some lua-magicians out here that know a much cleaner, better working solution to this.
All this is in one C lua_state* , so if there are any solutions adding this loadAPI function in C/C++ and just registrating it at the state this would be fine, too.
I've also looked at "require", but didn't seem to understand whether it does what I need.
Using Lua 5.2.3
Hope i didn't forget anything.
Thanks in advance :)
~InDieTasten
Try this:
function loadAPI(f,g)
_G[g]=setmetatable({},{__index=_G})
loadfile(f,"bt",_G[g])()
end
loadAPI("example.lua", "externAPI")
print(externAPI.apiFunction("Test"))

How can I create a subclass of a message (.msg) in OMNeT++?

I'm wondering whether it's possible to create a subclass of a message declaration (file *.msg which extends cPacket, see OMNeT++ Simulation Library). What I've tried so far is:
packet childPacket : parentPacket{...}
and
parentPacket childPacket {...}
which both can't be compiled by opp_msgc.
Thus, I haven't found a way so far to achieve this and I'm very thankful for any hints.
Cheers
- alex
The solution is really simple and most probably it just shows my lack of knowledge in c++ (I thought 'extend' was just used in java)...
Finally, I could achieve my goal described above by just typing
packet childPacket extends parentPacket{...}
Oh gosh, it's hot in herre...

Using Lua to define NPC behaviour in a C++ game engine

I'm working on a game engine in C++ using Lua for NPC behaviour. I ran into some problems during the design.
For everything that needs more than one frame for execution I wanted to use a linked list of processes (which are C++ classes). So this:
goto(point_a)
say("Oh dear, this lawn looks really scruffy!")
mowLawn()
would create a GotoProcess object, which would have a pointer to a SayProcess object, which would have a pointer to a MowLawnProcess object. These objects would be created instantly when the NPC is spawned, no further scripting needed.
The first of these objects will be updated each frame. When it's finished, it will be deleted and the next one will be used for updating.
I extended this model by a ParallelProcess which would contain multiple processes that are updated simultaneously.
I found some serious problems. Look at this example: I want a character to walk to point_a and then go berserk and just attack anybody who comes near. The script would look like that:
goto(point_a)
while true do
character = getNearestCharacterId()
attack(character)
end
That wouldn't work at all with my design. First of all, the character variable would be set at the beginning, when the character hasn't even started walking to point_a. Then, then script would continue adding AttackProcesses forever due to the while loop.
I could implement a WhileProcess for the loop and evaluate the script line by line. I doubt this would increase readability of the code though.
Is there another common approach I didn't think of to tackle this problem?
I think the approach you give loses a lot of the advantages of using a scripting language. It will break with conditionals as well as loops.
With coroutines all you really need to do is:
npc_behaviour = coroutine.create(
function()
goto(point_a)
coroutine.yield()
say("Oh dear, this lawn looks really scruffy!")
coroutine.yield()
mowLawn()
coroutine.yield()
end
)
goto, say and mowLawn return immediately but initiate the action in C++. Once C++ completes those actions it calls coroutine.resume(npc_behaviour)
To avoid all the yields you can hide them inside the goto etc. functions, or do what I do which is have a waitFor function like:
function waitFor(id)
while activeEvents[id] ~= nil do
coroutine.yield()
end
end
activeEvents is just a Lua table which keeps track of all the things which are currently in progress - so a goto will add an ID to the table when it starts, and remove it when it finishes, and then every time an action finishes, all coroutines are activated to check if the action they're waiting for is finished.
Have you looked at Finite State Machines ? If I were you I wouldn't use a linked list but a stack. I think the end result is the same.
stack:push(action:new(goto, character, point_a))
stack:push(action:new(say, character, "Oh dear, this lawn was stomped by a mammoth!"))
stack:push(action:new(mowLawn, character))
Executing the actions sequentially would give something like :
while stack.count > 0 do -- do all actions in the stack
action = stack:peek() -- gets the action on top of the stack
while action.over ~= true do -- continue action until it is done
action:execute() -- execute is what the action actually does
end
stack:pop() -- action over, remove it and proceed to next one
end
The goto and other functions would look like this :
function goto(action, character, point)
-- INSTANT MOVE YEAH
character.x = point.x
character.y = point.y
action.over = true -- set the overlying action to be over
end
function attack(action, character, target)
-- INSTANT DEATH WOOHOO
target.hp = 0
action.over = true -- attack is a punctual action
end
function berserk(action, character)
attack(action, character, getNearestCharacterId()) -- Call the underlying attack
action.over = false -- but don't set action as done !
end
So whenever you stack:push(action:new(berserk, character)) it will loop on attacking a different target every time.
I also made you a stack and action implementation in object lua here. Haven't tried it. May be bugged like hell. Good luck with your game !
I don't know the reasons behind you design, and there might be simpler / more idiomatic ways to it.
However, would writing a custom "loop" process that would somehow take a function as it's argument do the trick ?
goto(point_a)
your_loop(function ()
character = getNearestCharacterId()
attack(character)
end)
Since Lua has closures (see here in the manual), the function could be attached to your 'LoopProcess', and you call this same function at each frame. You would probably have to implement your LoopProcess so that that it's never removed from the process list ...
If you want your loop to be able to stop, it's a bit more complicated ; you would have to pass another function containing the test logic (and again, you LoopProcess would have to call this every frame, or something).
Hoping I understood your problem ...

Game NPC multi-action lua script design

I need to put scriptable NPC in my currect game project.
The project itself is developed in C++ language.
I will using Luabind to bind lua and c++.
I need to call NPC function when certain NPC clicked or timer to do something is activated.
Currently I stuck between 2 NPC script design.
Using a kind of npcname_action to differentiate every NPC.
This is kind of troublesome to give name to every different NPC.
I'm still thinking how to implement this in my project.
Example:
HotelBellboy12_Click() { .. }
HotelBellboy12_TimerAction() { .. }
Using name of function.
Every npc have it own lua file.
I'm thinking to load script into memory and when needed will be loaded into luaState using luaL_loadbuffer
Example:
OnClick() { .. }
OnTimerAction() { .. }
Which one is better and why?
You could use another design.
Take advantage of the fact that table keys and values can be any type.
Let's say npc is a table containing all NPC's. Its keys are NPC' names and its values are another table. This other table keys are the actions, and its values are the function for this actions.
So, if you want bob to jump when clicked on, and alice to cry after a timer, simply do :
npc.bob.click = function () jump() end
npc.alice.timer = function () cry() end
I've done something like this before and I used something similar to your #2 option. When the map loads I load a configuration Lua file containing all the NPC data; among that is the name of the script file used for the NPC.
When I need to load the NPC in the game I compile the Lua file. NPC's can use a 'model' NPC type to dictate most of the common behavior (for example a Merchant type or a Commoner type) which is specified in the NPC configuration. These model types provide all the basic functionality such as providing a trade window when clicked. The specific NPC's use functions like OnClick() to override their model and provide custom handlers.
This worked pretty well for me, although it ends up being a large volume of scripts if your game gets large.