Java or C ++ for my specific agent-based model (ABM)?

Unfortunately, I need to develop an agent-based model. My background is C ++; I am a decent, but not a professional programmer. My goal is to determine if my background forecast will be at the moment, the following algorithm will be faster or much easier to write in C ++ or Java.

  1. My agents will have a class Host. Their private member variables include their infection and immune status (type int) in relation to different strains. (In C ++, I can use unordered_mapor vectorto store this information depending on the number of strains.) I plan to keep track of all the hosts in the vector vector< Host *> hosts .
  2. The program will need to know at any time all the specific hosts infected with a particular strain or immunity to a particular strain. Therefore, for each strain, I could support two separate structures, for example, vector< Host *> immune and vector< Host *> infectious (I could make each two-dimensional, indexed by the strain, and then the owner).
  3. Hosts may die. It looks like this is creating a mess in C ++, because I need to find the right person to kill in Hostand search through other structures ( immuneand infectious) to find all the pointers to this object. I get the impression that Java will implicitly delete all of these pointers if I delete the underlying object. It's true? Is there a better way to do this in C ++ than what I have here?

Thanks in advance for any help.


, ++, . , , . ( , .)

, Java. , - , , (), , , , , .

+3
3
, Java , . ?

. ; , Java . (hosts, immune infectious), .

"" , ; a HashSet .


    private HashSet<Host> hosts;
    private HashSet<Host> immune;
    private HashSet<Host> infectious;

    public void killHost(Host deadManWalking) {
        hosts.remove(deadManWalking);
        immune.remove(deadManWalking);
        infectious.remove(deadManWalking);
    }

O (lg n) . ( equals hashCode Host, .)

++ , - ; ++ , . ++ ? , , , , Java rep ; . ? , , , , . ++ Java , ++. , Java, , . YMMV, natch, .

+1

,

, Java , .

Java ; , . ; , , .

+1

, : Java ( ) , . ().

, , , "" , . . , ++ , "" shared_ptr , weak_ptr . weak_ptr, shared_ptr, , . , , , weak_ptr shared_ptr , , ( ).

0

Source: https://habr.com/ru/post/1736374/


All Articles