Design for two interacting, extensible classes

Hi,
I have a design problem where I have two interacting classes that both need to be highly extensible. I'm pretty sure this not an uncommon problem but I can't really seem to find an appropriate pattern to implement it.
The problem comes from the field of reinforcement learning, where an Agent learns some task in an Environment by executing Actions based on the current State of the environment. The State has to be provided by the Environment, and the Action chosen by the Agent based on that State has to be executed on the Environment. I thus have an Environment interface (for multi-agent problems) like so:
public interface Environment {
     //execute given action for given agent (e.g., move the agent, let the agent pick up smth
        //in the env, etc), and return a reward
     public double executeAction( Action act, Agent a );
     //compute and return state of given agent (e.g., what the agent can currently see in the
       //environment)
     public State getState( Agent a );
}There can be many different types of environments, and many different types of actions. So I thought of having a callback method on the Action that the Environment calls in method executeAction, like:
public interface Action {
     //execute on the given environment for the given agent
     public void execute(Environment env, Agent a);
}In that case you could have the same environment (e.g., a world with blocks), and different actions (say move, push a block away, pick up a block, etc). Does this make any sense? It's a little like the Command pattern perhaps?
There are two things I'm worried about. One is that the Action would need to cast the received Environment to the right implementation, but I guess that's unavoidable. The other (actually two) is that the Environment implementation would need to expose the right methods for the action to be able to execute, plus I don't always want an Action to be able to do anything it wants with the environment (e.g. teleport the agent, remove all obstacles). On the other hand maybe I shouldn't worry about the latter since it's just meant to be a toolkit, so if people using it want to program actions to teleport the agent, that's their business.
Any suggestions/comments greatly appreciated.
Thanks
Matt

I am not a native english speaker, and I'm not sure I understand your description. Is the following pseudo-code a correct description of your design?No problem, me neither. Maybe that's why it was hard to understand :) Actually, an agent should by no means have direct access to the environment: it is only allowed to perceive things through the State object it receives. So the design is something like:
public interface Agent {
        //do a step: choose an action based on the current state, and learn from
        //the reward received after the last action.
     public Action doStep( State s, double reward );
public class Simulator {
        //do one simulation step
     public void doStep() {
          State s;
          Action act;
          for ( Agent a : agents ) {
                        //get the agent's state from the environment
               s = env.getState(a);
                        //let the agent choose an action based on that state (lastReward is stored in a Map, omitted)
               act = a.doStep(s, lastReward);
                        //execute action on the environment and store the reward for this agent
               lastReward = env.executeAction(act, a));
There are two things I'm worried about. One is that the Action would need to cast the received Environment to the right implementation, but I guess that's unavoidable.Why? Cant he environment interface define abstract "modifier" methods that make sense to all implementations?Not really. An environment can be anything: a world with objects that the agent has to collect/avoid (I chose that example because I thought it might be easy to visualise and understand). A Blackjack game in which the agent has to choose to get another card or stop. The stock market in which the agent has to make trading decisions. And so on.
And iff the actions are specific to some environment implementations, then each environment can implement executeAction his way, for example calling different Action methods. In this case the Action become merely a Visitor.Yes, I indeed looked at the Visitor pattern, but I think it's not flexible enough. The types of the environments / actions need to be known beforehand, and in my case they can be anything.
The other (actually two) is that the Environment implementation would need to expose the right methods for the action to be able to execute, plus I don't always want an Action to be able to do anything it wants with the environment (e.g. teleport the agent, remove all obstacles).Method executeAction should use only those methods exposed in interface Environment (which is the type of the env argument).
If the Action and Agent implementations need some different views of the environments, just define two different interfaces.Hmm, yes. The problem is that the Environment interface should pretty much only specify those methods that I listed. Those are the methods necessary for the reinforcement learning paradigm (basically as implemented in the Simulator). Adding additional, problem-specific methods to that interface would not make sense, because environments can be anything. But, perhaps I could do something like:
public interface BlockWorld {
     public boolean move(Block b);
     public Block getBlockAt(int x, int y);
public class SomeWorld implements Environment, BlockWorld {}
public class PushAction implements Action {
     @Override
     public void execute(Environment env, Agent a) {
                //unavoidable (?) cast
          BlockWorld world = (BlockWorld) env;
          //get the block that the agent is facing, and move it
          //as specified in the action
}So define an interface according to the methods the world wants to expose. The only concern is that the same world (with obstacles and what not) could be used in a lot of different contexts, and I guess it's not desirable to subclass it every time just to make it implement an additional interface because one wants to expose different methods. But maybe I can use the Adapter pattern for this?

Similar Messages

  • Rack design for two ONS 15454's and two 15540-PWR-AC power supplies...

    Looking for advice setting up two ONS boxes with two 15540-PWR-AC power supplies. The manuals/CCO show rack design for just the ONS boxes and a fuse/alarm panel. I have two side by side racks for the gear. Has anyone set up the power supplies for an ONS installation? Any feedback would be great.
    thx.
    - Ted

    Review the AC/DC Power Solution Data Sheet:
    http://www.cisco.com/en/US/products/ps6063/products_data_sheet0900aecd801a002a.html
    Per the Data Sheet...
    The Medium will power 1x 15454
    The Large will power 2x 15454
    A few things to note...
    1. The Power Solution can possibly power more 454s based on the actual power draw of the nodes.
    2. There are only 4 circuit breakers on the Large expansion panel. A & B power for 2 454s.
    3. It is recommended 454s have 30A fuses/breakers per power source. This can change based on the actual hardware config.
    4. You could possibly use the 15A GMT fuses.
    5. You could possibly incorporate an external PDU for additional fuses.

  • Design for two different JVM

    Hi,
    I would like to design my java application which will run on both java SE & ME jvm. This application will be invoked by the c++ using JNI. Actually all business logic is in the JAVA application and c++ will do the JNI communication for the same. However here only JNI communication layer will be different for both SE and ME jvms, other wise rest of the modules will remain same for both JVMs. Actually some proprietary JNI communication module is in place for java ME which we need to use when same application will be run on the java ME otherwise we need to write our own communication logic for the java SE jvm. How can I design java application so that it will be compatible for both the JVMs.

    user3516155 wrote:
    So How can I design the application?I believe I already answered that - use a communication layer.
    If you are asking (different than your original question) about how your communication layer might implement similar functionality using different APIs supported by the VM then the same basic idea applies - provide a layer, code to the layer and implement the layer different for each platform.
    Note however that it is foolhardy to carry this to an extreme. Don't wrap trivial functionality to gain minimal gains because it increases complexity and thus maintenance costs.

  • How to create two different implementation class for a Control

    Hi,
    I am a newbie to beehieve. I want to know that is it possible to create two different 'Impl' classes for a Control. If yes then how do we instantiate them ? How can we chain them (something like calling one 'Impl' from the other one? Thanks in Advance!!!
    Regards,
    Abhishek

    You are sure you are in the right forum?
    This is the JDeveloper and ADF forum...
    Timo

  • Filter Information for two parameters in Query Designer

    Hi Gurus !!
    I have a problem for filter information for two parameters in Query Designer,
    the first parameter correspond a Ejercise-Period, the second parameter correspond
    a Compensation Date of document, both parmeters must have date less than or equal to
    to the parameter date input for screen (mm.aaaa).
    Internally the Report must filter countable information for Countable Date <= Parameter Input and
    Compensation Date of document <= Parameter Input.
    If i assign two filter parameter in Query Designer, not could realise this.
    Exist any simple form to realise this ??
    Wait for yours responses.
    Thank You.

    Hi shanthi bhaskar,
    Thanks a lot for your answer.
    I have one doubt about it:  with this solution that you propoused the user will be able to select the values for plant?.
    I mean, the user make the selection of the value for Zone, then he wants to see the in plan´s variable the values that corresponds with this Zone for make a new selection of plan.
    What happens if I need this dependency also in another variable like time variable?
    Thanks  a lot

  • Proper object oriented design for factory class

    I have a factory class (UserFactory) it is capable of creating two types of classes (Customer and Employee) that extend User. User is an abstract class.
    At present any class could create a Customer of an Employee.
    How do I restrict access to the constructors of Customer and Employee only to UserFactory?
    I don't want to make both of these classes interfaces (in which case I could just have UserFactory implement both of them).
    Here is an example of how they are set up at present:
    public abstract class User {
    public class Customer extends User{
    public Customer{
    public class Employee extends User {
    public Employee {
    public class UserFactory ???? {
    private static UserFactory c_userFactory = null;
    private UserFactory (){
    public UserFactory getInstance(){
    //private clone method too
    public Customer createCustomer(){
    public Employee createEmployee(){
    Oh and I don't want to create two separate factory classes for Employee and Customer. In C++ there is a concept of friend classes that would have worked nicely in this case.
    Thanks for any and all suggestions,
    Tim

    So correct me if I'm wrong but your suggestion would be something along the lines of:
    public abstract class User {
    public class Customer extends User{
    protected Customer(){
    public class Employee extends User {
    protected Employee (){
    public class UserFactory ???? {
    private static UserFactory c_userFactory = null;
    private UserFactory (){
    public UserFactory getInstance(){
    //private clone method too
    public Customer createCustomer(){
    public Employee createEmployee(){
    public class AccessForCustomer extends Customer {
    public class AccessForEmployee extends Employee {
    Is the above about what you were talking about? I haven't used inner classes before, so I'm a bit curious. Does this mean no class other than UserFactory or derivatives thereof can access the two classes AccessForCustomer and AccessForEmployee?
    Thanks,
    Tim

  • Two different accounts to be posted for the same valuation class on PGI

    Hi Experts,
    Please note that we want to post two different accounts for the stock offset entry( based on the nature of customer ) in the transaction of PGI in SO. However the valuation class is the same as the nature of the material is same (only the nature of customers is different). We have put one of the two accounts in OBYC GBB - VAX and GBB - VAY.
    Is it possible to have two offset accounts on PGI for the same valuation class.If yes, how will the system identify which one to be posted to.
    Thanks in advance for answers..
    KJU

    hi
    why not create two asset class to easily to separate two situations for two company codes? just a suggestion
    or
    maintain one depreciation key for asset class as a default, if for another company code, just change the depreciation key manual when creating asset master. it is not very complicate.
    or
    create two depreciation areas, one for each company code, then, you will have one useless depreciation for each company code -- not a resonable way
    and, yes, that is the limitation of substituion in AA.
    best regards, Lawrence

  • SCTL-NFC1 is a Near Field Communication(NFC)/Radio Frequency Identification(RFID) Reader and Payment Adaptor designed for iPhone/iPod Touch to provide NFC two-way communication,RFID read/write and contactless payment capabilities.

    SCTL-NFC1 is a Near Field Communication(NFC)/Radio Frequency Identification(RFID) Reader and Payment Adaptor designed for iPhone/iPod Touch to provide NFC two-way communication,RFID read/write and contactless payment capabilities.
    commercial applications such as asset tracking, document tracking, healthcare, security and access control.

    We are the manufactuer of the reader

  • Is this the best design for asynchronous notifications (such as email)? Current design uses Web Site, Azure Service Bus Queue, Table Storage and Cloud Service Worker Role.

    I am asking for feedback on this design. Here is an example user story:
    As a group admin on the website I want to be notified when a user in my group uploads a file to the group.
    Easiest solution would be that in the code handling the upload, we just directly create an email message in there and send it. However, this seems like it isn't really the appropriate level of separation of concerns, so instead we are thinking to have a separate
    worker process which does nothing but send notifications. So, the website in the upload code handles receiving the file, extracting some metadata from it (like filename) and writing this to the database. As soon as it is done handling the file upload it then
    does two things: Writes the details of the notification to be sent (such as subject, filename, etc...) to a dedicated "notification" table and also creates a message in a queue which the notification sending worker process monitors. The entire sequence
    is shown in the diagram below.
    My questions are: Do you see any drawbacks in this design? Is there a better design? The team wants to use Azure Worker Roles, Queues and Table storage. Is it the right call to use these components or is this design unnecessarily complex? Quality attribute
    requirements are that it is easy to code, easy to maintain, easy to debug at runtime, auditable (history is available of when notifications were sent, etc...), monitor-able. Any other quality attributes you think we should be designing for?
    More info:
    We are creating a cloud application (in Azure) in which there are at least 2 components. The first is the "source" component (for example a UI / website) in which some action happens or some condition is met that triggers a second component or "worker"
    to perform some job. These jobs have details or metadata associated with them which we plan to store in Azure Table Storage. Here is the pattern we are considering:
    Steps:
    Condition for job met.
    Source writes job details to table.
    Source puts job in queue.
    Asynchronously:
    Worker accepts job from queue.
    Worker Records DateTimeStarted in table.
    Queue marks job marked as "in progress".
    Worker performs job.
    Worker updates table with details (including DateTimeCompleted).
    Worker reports completion to queue.
    Job deleted from queue.
    Please comment and let me know if I have this right, or if there is some better pattern. For example sake, consider the work to be "sending a notification" such as an email whose template fields are filled from the "details" mentioned in
    the pattern.

    Hi,
    Thanks for your posting.
    This development mode can exclude some errors, such as the file upload complete at the same time... from my experience, this is a good choice to achieve the goal.
    Best Regards,
    Jambor  
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Two Interactive Report in the same page

    I created two interactive report following the suggestion this link
    http://roelhartman.blogspot.com/2009/03/two-interactive-reports-on-one-page.html
    using an IFRAME
    <IFRAME src="f?p=&APP_ID.:24:&SESSION."
    style="width:600px;height:600px"
    name="details"
    scrolling="no" marginwidth="0" marginheight="0"
    frameborder="0" vspace="0" hspace="0" />
    I am facing two problems.
    a. I could see the logo attached to the application in the IFRAME window
    b. I could not see the lower bound of the region where the IFRAME is assigned to.
    Any suggestion would be of great help.
    Thanks in advance
    Deb

    Hi,
    For your first issue.
    Use page template to iFrame page that do not contain substitution string LOGO.
    E.g. popup page template might not have that.
    Or create your own page template with minimal set of substitution strings and regions and use that for iFrame page
    Regards,
    Jari

  • Using a variable for two different characteristic

    Hello
    I've to following situation:
    1) While execuring a query in BEx Analyzer, the user should manually enter a specific key date KEY_DATE
    2) Then, two InfoObjects should be restricted by using that KEY_DATE as follows
         a) InfoObject BEG_DATE <= KEY_DATE
         b) InfoObject END_DATE > KEY_DATE
    So, in Query Designer I've created a variable KEY_DATE and added it to each of the above InfoObjects. Now, while executing the query I get an error: "Variable KEY_DATE is used for two different characteristics".
    Is there another possibility to realize my requirements?

    Hi Dear,
             create variable for that date and restrict the char. info object by that date.
    -->create a variable of date char.
    -->in General tab, select processing by Replacement path
    -->in replacement path , offset 0 and lenght 0
    -->ok
    when u restrict, select value ranges and select greater than for one and less than equal for another
    try and let me know if any probm...
    Regards
    Obaid

  • AT NEW command for two fields

    Dear All,
    How to use AT NEW command in internal table for two fields.
    Warm Regards,
    N.Jain

    Hi
      See the following code. It is useful for u.
    DATA: BEGIN OF ty_batest,
            designation TYPE zba_test-designation,
            salary TYPE zba_test-salary,
            empno TYPE zba_test-empno,
            empname TYPE zba_test-empname,
            address TYPE zba_test-address,
          END OF ty_batest,
          it_batest LIKE TABLE OF ty_batest,
          wa_batest LIKE ty_batest.
    SELECT * FROM zba_test INTO CORRESPONDING FIELDS OF TABLE it_batest.
    SORT it_batest BY designation salary.
    LOOP AT it_batest INTO wa_batest.
      AT NEW designation.
        WRITE: / 'Designation  :', wa_batest-designation,
               /(35) sy-uline.
      ENDAT.
      AT NEW salary.
        WRITE: / 'Salary : ', wa_batest-salary,
      ENDAT.
      WRITE: / 'Emp Name    : ', wa_batest-empname,
              / 'Emp Number  : ', wa_batest-empno,
              / 'Designation : ', wa_batest-designation,
              / 'Address     : ', wa_batest-address,
              / 'Salary      : ', wa_batest-salary NO-ZERO .
      SKIP.
    ENDLOOP.
    Regards
    Bhuvana.

  • I took out a 1 month Zoosk subscription in 2012. I cancelled in my ipad setting but Zoosk have still been charging me for two years!!!

    Back in 2012 I took out a 1 month zoosk subscription through my ipad and quickly found that it auto-renewed after the first month. I contacted zoosk and asked them to cancel the subscrip. They said they couldnt do it and I had to cancel the subscript via my apple ID and manage subscritpions in ipad setting. So I did this and the ipad showed me my subscription had been cancelled. I thought all was well and good. until by accident I noticed this week on my bank statement I have a charge of £22.74. After a little more investigation I founf that this has been the case for the last two years. I logged into zoosk which has confirmed my subscription was never cancelled and I have been paying £22.74 for the last two years.
    I have contacted apple itunes about this and have not heard a anything bird form them. I have also contacted zoosk several times and still heard nothing. I now have the fraud team from my bank investigating! It seems that apple want no part in protecting us from these sites...
    I advise you now, PLEASE WHAT EVER YOU DO DONT TAKE OUT A SUBSCRIPTION WITH ZOOSK. THE GIRLS ARE EITHER EASTERN EUROPEAN FAKERS USING THE SITE OR JUST PLAIN FAKE PROFILES AND THE COMPANY ARE FRAUDSTERS!  AVOID AVOID AVOID!!!!!

    As I told you in the other thread, you have to file the claim with the Small Claims Court now. You only have just over a month to file the claim (Limitation Act 1980: 6 years for England and Wales, 5 for Scotland, so if you are in Scotland, you have effectively lost your 1st year's amount).
    Your amount is below the limit of £5000 and you can easily file the claim online. You said you have a book keeper, so I assume you will have all the paperwork on hand/filed away nicely. This will make your case easy to prove. You are not only allowed to claim the amount taken unlawfully from you (the mods here do not like the word stolen), but also your court fees and an 8% PA interest on the amount. You can also claim other costs in trying to recover your money from BT; for exampe a "reasonable" amount of money for your time, phone charges to BT, postage if you wrote to them, cost of paper, ink, etc...
    Note that legal fees are not claimable in the small claims court, but you can easily find help on how to fight without legal representation elsewhere on the internet. Do not worry about not having legal representation if the case does go to court, the Small Claims Court is design for "little people" to fight the bullies.
    Good luck and you will feel great when the cheque arrives (ask me how I know!).

  • How to Design an Adobe Interactive form

    Hi,
    I want to design a Adobe interactive form .
    I could not find different type of Layout for designing a page.
    can any one let me know the availability of such Layout in Interactive forms ?
    Also, i want to fill the values in the text fields of Intercative form by using BAPI and Can anyone suggest me how to achieve this .
    Thanks in advance,
    Best regards,
    Debasish

    hi
    try this tutorial on
    online interactive
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tutorial on online interactive pdf form - 29.htm
    for offline interactive form
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tutorial on offline interactive pdf form using download - 30.htm
    for downloading and uploading pdf forms
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tutorial on offline interactive pdf form using e-mail - 31.htm
    regards
    saravana

  • Not able to assemble two interactive PDF forms to form a single interactive PDF

    Hi,
    I am trying to assemble two interactive PDF forms to form a single PDF. I am using LiveCycle process with Assembler and Invoke ddx file for this. But the resultant PDF is a flattened non interactive file.
    Please guide me in obtaining a interactive PDF from two interactive PDFs.
    Thanks in Advance,
    Shabeer

    Sabeer,
    type of output document depends on the type of base document.
    if base document is flatten\non-intractive, then you will recieve flatten\non-intractive form nd vise versa
    ddx,
    <PDF result="doc3.pdf" ><!--output document; intractive-->
         <PDF source="doc1.pdf"/> <!--Base document; intractive-->
         <PDF source="doc2.pdf"/>
    </PDF>
    Regards
    Sunil Gupta

Maybe you are looking for

  • Using DBMS_AQ package in APEX

    Hello, I am trying to create a Queue table from application express. I read through a post on another forum that said some privs must be granted before a queue table can be created. They are: GRANT RESOURCE TO <UserName>; GRANT CONNECT TO <UserName>;

  • The Nordins - Options for the next time you need a customer!

    The headline is from an email we received: "Verizon - Options for the next time you need customer service!"  Well, we changed it, just slightly.   Well, on 6/20/2013 we had the TV down; it was said to be a piece of video equipment that went down.  We

  • Procedures for implementing a snapshot scenario with custom DataSources

    Hi Gurus, I have checked the How To paper ([How to Handle Inventory Management Scenarios in BW (NW2004)|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/f83be790-0201-0010-4fb0-98bd7c01e328]). However, only SAP standard BW objects are mentioned

  • What is username and password for sqlplus?

    For oracle8.1.7: I tried using the following username/password to open sqlplus,but all failed: system/manager internal/oracle scott/tiger The error message is:ORA-12560 Please help me!!! Thanks!

  • How to use snapshots

    hello we want to do replication of database, but since we are having std edition it seems it may not be possible to go ahead with this idea. snapshot might be one possbile way. i just wanted to know if we are having 500 tables in our database how can