Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:06:23+00:00 2026-05-31T20:06:23+00:00

I am using ECJ (an evolutionary algorithms package) and I want to call certain

  • 0

I am using ECJ (an evolutionary algorithms package) and I want to call certain variables that are in an extended class but I can’t figure out how to get to them from the problem class.

As you can see in the problem class below I want to be able to call the variable x in the NetworkGene class but it doesn’t work because I end up in the VectorGene class in which I can only call variable y.

class Problem {
  double fitness = 0;
  public void evaluate(final Individual ind){
    if(!(ind. instanceOf GeneVectorIndividual)){
      state.output.fatal("Not a GeneVectorIndividual",null);
    }
    fitness = 0;
    for(){
      fitness += ind.genome[i].x;
    }      
  }
}

public abstrabct class VectorIndividual extends Individual{
}

public class GeneVectorIndividual extends VectorIndividual{
  VectorGene[] genome;
}

public abstract class VectorGene implements Prototype {
  double y;
}

public class NetworkGene extends VectorGene{
  double x;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:06:24+00:00Added an answer on May 31, 2026 at 8:06 pm

    Classic polymorphism problem.

    The quick and dirty solution is this: in the for loop in class Problem, add these lines

    if (ind.genome[i] instanceof NetworkGene) {
        fitness += ((NetworkGene) ind.genome[i]).x;
    }
    

    But probably there’s a design problem you need to solve:

    Why is ind.genome an array of VectorGenes instead of NetworkGenes?

    What does x represent? Is there something you could express within VectorGene like a method getSomeValue() which in NetworkGene you would implement to return x (and in other subclasses you’d implement it to return some other appropriate value)?

    Do you really need the inheritance relationship between VectorGene and NetworkGene – does it relate to some difference that you actually need to exploit in the problem you are currently trying to solve? Couldn’t you just have a single class containing properties x and y?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
First suppose that I have an abstract class, let's call it AbstractClass. Suppose public
Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But -
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A
Using jQuery, one can easily find out whether a particular element is visible using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.