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 9115075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:20:41+00:00 2026-06-17T04:20:41+00:00

This is a simple problem, but I would like suggestions on how to solve

  • 0

This is a simple problem, but I would like suggestions on how to solve it. I have a Policy class with constructor Policy::Policy(const int& mode).

Depending on the value of mode, the Policy object can have different behavior and characteristics. For example, let’s say there are 3 possible modes of running my program corresponding to mode=1, mode=2, and mode=3. Now, at no time would there ever be Policy objects with different mode values.

So, it makes sense to me that there would be a variable static int Policy::MODE so that all Policy objects know what mode they should be running under. The very first Policy object created would set in its constructor the value of this static class variable. Then, if any other Policy objects are attempted to be created with a different value of mode, the instantiation would exit with an error (because this should not ever be happening).

Any suggestions on how to solve this problem?

[Additional explanation added below in response to comment request.]

The program is for optimizing disease-screening policies. Each Policy object represents a screening policy and has a lot of features necessary in order to keep track of statistics that reflect the impact of practicing that policy in a population. In the parlance of optimization, each screening policy is a vector of decision variables and the objective function is estimated by simulating the policy using a natural history model of the disease.

The Policy object needs to be able to seamlessly fit within multiple complicated optimization frameworks. It needs to be able to represent not only disease-screening policies, but also any number of standard test problems that can be used to test whether the optimization algorithms are working well. The features/characteristics that change based on the MODE value of the Policy class are the following: (1) the simulation model used to evaluate the policy, (2) the code in the constructor that sets up things such as the length of the decision variables vector, and (3) the code used to display information about a given policy and its estimated performance.

For any particular simulation model (i.e. objective function), there are multiple “policy expressions” (i.e. vectors of decision variables) which can be decoded to the policy expression required by the simulation model. So, each “mode” represents a pairing of a way of expressing a screening policy with a particular simulation model to evaluate that policy.

Leaving out a lot of non-relevant things, here would be the structure of the class if there were just 2 different modes of running:

class Policy {
public:

    vector<double> x; // encoded representation of a policy (decision variables)

    explicit Policy(const int& mode) {

        // set Policy::MODE if not already set (code not shown)

        switch(MODE) {
        case 1:
            // code...
            break;
        case 2:
            // code...
            break;
        }
    }

    void simulate() {

        switch(MODE) {
        case 1:
            // code...
            break;
        case 2:
            // code...
            break;
        }
    }

    void displayInfo() {

        switch(MODE) {
        case 1:
            // code...
            break;
        case 2:
            // code...
            break;
        }
    }

private:
    static int MODE;
};

At a high level, you could say that each mode value represents the pairing of a solution with an estimator.

  • 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-06-17T04:20:42+00:00Added an answer on June 17, 2026 at 4:20 am

    Are you asking for something like that:

    static int Policy::MODE=-1;
    Policy::Policy(const int& mode) {
      if (MODE==-1) {
        MODE=mode;
      }
      else {
        if (mode!=MODE) {
          cout <<"mode mismatch "<<...<<endl;
          exit (1); // or throw something, set some flags, depending on your needs
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys having this really simple problem but cant seem to figure out have
this may seem like a simple problem but I couldn't find it in the
All, this seems like a simple problem but it's giving me fits. Lets say
I'm guessing this is a simple problem, but I'm just learning... I have this:
this must be such a simple problem but can someone tell me why this
This is a seemingly simple problem but I am having trouble doing it in
Maybe this is a simple problem, but I am just not seeing it :)
This is a really simple problem, but I couldn't find a solution anywhere. I'm
This is such a simple problem, but I can't find an answer anywhere... I
There must be a simple solution to this problem but for the love of

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.