Click here to Skip to main content
15,180,782 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: .NET 5? Pin
Doug Milne 202111-Aug-21 8:45
MemberDoug Milne 202111-Aug-21 8:45 
GeneralRe: .NET 5? Pin
D. Milne24-Aug-21 7:59
MemberD. Milne24-Aug-21 7:59 
GeneralRe: .NET 5? Pin
Richard MacCutchan24-Aug-21 22:45
mveRichard MacCutchan24-Aug-21 22:45 
QuestionHow can I update my status-bar in MFC? Pin
Member 1503370431-Dec-20 22:03
MemberMember 1503370431-Dec-20 22:03 
AnswerRe: How can I update my status-bar in MFC? Pin
Richard MacCutchan31-Dec-20 22:19
mveRichard MacCutchan31-Dec-20 22:19 
QuestionAdding references to WPF or WinForms in .NET 5 (from C++/CLI) Pin
John Schroedl18-Dec-20 6:11
professionalJohn Schroedl18-Dec-20 6:11 
AnswerRe: Adding references to WPF or WinForms in .NET 5 (from C++/CLI) Pin
John Schroedl18-Dec-20 8:34
professionalJohn Schroedl18-Dec-20 8:34 
Question“error:passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]” Pin
neuronphysics13-Dec-20 17:35
Memberneuronphysics13-Dec-20 17:35 
I am trying to apply DESPOT POMDP solver with using given examples to build my own decision making problem and I followed the documentation in the repository to build different relevant classes and functions in the header file

C++
class SimpleState: public State {
    public:
            int position; 
            int context;
            int time;
    
            SimpleState();
            SimpleState(int _position, int _context, int _time) :
            rat_position(_position),
            context(_context),
            time(_time) {
            }
            SimpleState(int _state_id);
            ~SimpleState();
    
            std::string text() const;
    };
        SimpleState::SimpleState() {
        }

    class StarMazeProblem : public DSPOMDP,
         public MDP {
    protected:
            std::vector<std::vector<std::vector<State> > > transition_probabilities_; //state, action, [state, weight]
    
            mutable MemoryPool<SimpleState> memory_pool_;
    
            std::vector<SimpleState*> states_;
    
            mutable std::vector<ValuedAction> mdp_policy_;
    
    public:
            enum {CENTER = 0, RIGHT = 1, LEFT = 2};
            
    public:
          StarMazeProblem();
          int NumStates() const;
          void ComputeDefaultActions(std::string type)  const;
          ParticleUpperBound* CreateParticleUpperBound(std::string name = "DEFAULT") const;//?
          ScenarioUpperBound* CreateScenarioUpperBound(std::string name = "DEFAULT",
                  std::string particle_bound_name = "DEFAULT") const;
    
          ScenarioLowerBound* CreateScenarioLowerBound(std::string name = "DEFAULT",
                  std::string particle_bound_name = "DEFAULT") const;
         }

and in the `starmaze.cpp` file the relevant lines are

C++
int StarMazeProblem::NumStates() const {
    	 return CONTEXT * POSITIONS * TIME;
    }
    void StarMazeProblem::ComputeDefaultActions(string type) const {
    	cerr << "Default action = " << type << endl;
    	if (type == "MDP") {
    		const_cast<StarMazeProblem*>(this)->ComputeOptimalPolicyUsingVI();
    		int num_states = NumStates();
    		default_action_.resize(num_states);
    
    		double value = 0;
    		for (int s = 0; s < num_states; s++) {
    			default_action_[s] = policy_[s].action;
    			value += policy_[s].value;
    		}
    	} else {
    		cerr << "Unsupported default action type " << type << endl;
    		exit(0);
    	}
    }
    ScenarioLowerBound* StarMazeProblem::CreateScenarioLowerBound(string name,
                                         string particle_bound_name="DEFAULT") const {
            const DSPOMDP* model = this;
    	    const StateIndexer* indexer = this;
    	    const StatePolicy* policy = this;                                 
            ScenarioLowerBound* bound = NULL;
            if (name == "TRIVIAL" ) {
                bound = new TrivialParticleLowerBound(this);
            } else if (name == "RANDOM") {
                bound = new RandomPolicy(this,
                              CreateParticleLowerBound(particle_bound_name));
            } else if (name == "MODE" || name == "DEFAULT") {
    		    ComputeDefaultActions("MDP");
    		     bound = new ModeStatePolicy(model, *indexer, *policy,
    			              CreateParticleLowerBound(particle_bound_name));                             
            }  else {
                cerr << "Unsupported scenario lower bound: " << name << endl;
                exit(1);
            }
            return bound;
    }


here I got the following error for the above code:

C++
src/starmaze.cpp:301:36: error: passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]
       default_action_.resize(num_states);
                                        ^
    In file included from /opt/local/include/gcc7/c++/vector:64:0,
                     from ../../../include/despot/interface/lower_bound.h:4,
                     from ../../../include/despot/core/builtin_lower_bounds.h:4,
                     from src/starmaze.h:3,
                     from src/starmaze.cpp:1:
    /opt/local/include/gcc7/c++/bits/stl_vector.h:689:7: note:   in call to 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
           resize(size_type __new_size)
           ^~~~~~

I have basic c++ knowledge and I could not figure out the reason for the error since I followed the examples. Any suggestion?
Questionap alternate boundary pairs in matrix Pin
Doraemon Kids25-Nov-20 9:26
MemberDoraemon Kids25-Nov-20 9:26 
AnswerRe: ap alternate boundary pairs in matrix Pin
Richard MacCutchan25-Nov-20 10:24
mveRichard MacCutchan25-Nov-20 10:24 
QuestionAbstract classes and factories Pin
Richard Andrew x6412-Sep-20 6:53
professionalRichard Andrew x6412-Sep-20 6:53 
Questionsorce code grid line Pin
SADEGH20771-Aug-20 8:32
MemberSADEGH20771-Aug-20 8:32 
AnswerRe: sorce code grid line Pin
Dave Kreskowiak1-Aug-20 9:41
mveDave Kreskowiak1-Aug-20 9:41 
QuestionCreating an OpenGL view on a Windows Form Pin
SADEGH207730-Jul-20 9:05
MemberSADEGH207730-Jul-20 9:05 
QuestionOPENGL 4.6 Not responsive please help Pin
SADEGH207730-Jul-20 7:13
MemberSADEGH207730-Jul-20 7:13 
AnswerRe: OPENGL 4.6 Not responsive please help Pin
Richard Andrew x6430-Jul-20 7:42
professionalRichard Andrew x6430-Jul-20 7:42 
QuestionTO OPENGL 4.6 Not responsive please help Pin
SADEGH207730-Jul-20 7:09
MemberSADEGH207730-Jul-20 7:09 
QuestionI want to use this source code that you put, but with opengl 4.6 Does not run and gives an error Pin
SADEGH207730-Jul-20 6:36
MemberSADEGH207730-Jul-20 6:36 
AnswerRe: I want to use this source code that you put, but with opengl 4.6 Does not run and gives an error Pin
Richard MacCutchan31-Jul-20 5:52
mveRichard MacCutchan31-Jul-20 5:52 
QuestionCreating an OpenGL view on a Windows Form Pin
SADEGH207730-Jul-20 4:54
MemberSADEGH207730-Jul-20 4:54 
AnswerRe: Creating an OpenGL view on a Windows Form Pin
Richard MacCutchan30-Jul-20 5:15
mveRichard MacCutchan30-Jul-20 5:15 
Questionc++ program Pin
Member 148568768-Jun-20 3:31
MemberMember 148568768-Jun-20 3:31 
AnswerRe: c++ program Pin
Eddy Vluggen8-Jun-20 4:01
professionalEddy Vluggen8-Jun-20 4:01 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 5:27
MemberMember 148568768-Jun-20 5:27 
GeneralRe: c++ program Pin
Eddy Vluggen8-Jun-20 6:13
professionalEddy Vluggen8-Jun-20 6:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.