473,772 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

program exit, while trying to initialize a class

Hi

I have a runing error while trying to initialize a class.
this is my code:

main.C
-------------
#include "tdagent.H"
#include "simple_env .H"
#include <vector>

int main()
{
simple_env *env;
env = new simple_env();
env->create();
tdagent *agent;
agent = new tdagent(env);
....
}
tdagent.H
------------------

#ifndef TDGAENT_H
#define TDAGENT_H

#include "critic.H"
#include "actor.H"
#include "simple_env .H"

class tdagent
{

private:

ublas::vector<f loat> get_state();
ublas::vector<f loat> get_previous_st ate();
void set_previous_st ate(ublas::vect or<float> curr_state);
float get_reward();
simple_env* env;
critic* critic1;
actor* actor1;
float d;
state x;

public:
tdagent(simple_ env* environment);
~tdagent();
std::vector<flo at> find_next_actio n();
};

#endif

tdagent.C
------------------
#include "tdagent.H"

tdagent::tdagen t(simple_env* env)
: critic1(new critic(env->get_cov(),en v->get_state()) ),
actor1(new actor(env->get_cov(),en v->get_state(),
env->get_actions_nu m(),
env->get_min_reward (),env->get_max_reward ()))
{
x.prev=get_stat e();
}

.....

The code compiled fine.
But when I tried to run it I got:

"Aborted (core dumped)"

I tried to debug it using ddd, and I saw that the program exits at:
"agent = new tdagent(env);"
at main.C
when trying to step into this function I get to
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iostream

I'm using Cygwin g++ 3.4.4

I don't understand where is my mistake.
Hope you can help me find it.

Thanks for your help.
Dvir.

Jun 7 '06 #1
4 1921
In message <11************ **********@j55g 2000cwa.googleg roups.com>, dvir
<sc*****@gmail. com> writes
Hi

I have a runing error while trying to initialize a class.
this is my code:
[snip incomplete code]
I don't understand where is my mistake.
Hope you can help me find it.


That's unlikely, since you haven't shown any of the member functions of
simple_env, critic or actor.

Post a minimal _complete_ program that illustrates the problem.

--
Richard Herring
Jun 7 '06 #2

Ok here is a more complete version of the code.
hope its more clear now.

main.C
------------
#include "tdagent.H"
#include "simple_env .H"
#include <vector>

int main()
{
simple_env *env;
env = new simple_env();
env->create();
tdagent *agent;
agent = new tdagent(env);
....
}

simple_env.H
---------------------
#ifndef SIMPLE_ENV_H
#define SIMPLE_ENV_H

#include <math.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix_proxy.hp p>
#include <boost/numeric/ublas/vector_proxy.hp p>

#define PI 3.1415926535897 932384626433832 795

class simple_env
{
public:
simple_env();
~simple_env();
void create();
float preform(float u);
float get_reward();

boost::numeric: :ublas::vector< float> get_state();
boost::numeric: :ublas::vector< float> get_previous_st ate();
boost::numeric: :ublas::vector< float> get_final_state ();
boost::numeric: :ublas::vector< float> get_cov();
int get_actions_num ();
float get_min_reward( );
float get_max_reward( );

private:
float sigmoid(float u);
float reward;
boost::numeric: :ublas::vector< float> state;
boost::numeric: :ublas::vector< float> prev_state;
boost::numeric: :ublas::vector< float> final_state;
boost::numeric: :ublas::vector< float> cov;
};

#endif
simple_env.C
---------------------
#include "simple_env .H"

namespace ublas = boost::numeric: :ublas;
using namespace boost::numeric: :ublas;

simple_env::sim ple_env()
{

reward=0;
}

simple_env::~si mple_env()
{

}

void simple_env::cre ate()
{
cov.resize(3);
for (unsigned int i = 0; i < 3; ++ i)
cov (i) = 1;
vector<float> initial_state(3 );
for (unsigned int i = 0; i < initial_state.s ize (); ++ i)
initial_state (i) = 0;

final_state.res ize(3);
for (unsigned int i = 0; i < final_state.siz e (); ++ i)
final_state (i) = 5;

state=initial_s tate;

return;
}

ublas::vector<f loat> simple_env::get _cov()
{
return cov;
}
float simple_env::pre form(float u)
{

prev_state=stat e;
for (unsigned int i = 0; i < state.size (); ++ i)
state (i) += sigmoid(u);
reward=norm_2(s tate);

return reward;

}

float simple_env::get _reward()
{
return reward;
}

ublas::vector<f loat> simple_env::get _state()
{
return state;
}

ublas::vector<f loat> simple_env::get _final_state()
{
return final_state;
}
ublas::vector<f loat> simple_env::get _previous_state ()
{
return prev_state;
}

float simple_env::sig moid(float u)
{
float s;
s=PI/2*atanf(2/PI*u);
return s;
}

int simple_env::get _actions_num()
{
return 1;
}

float simple_env::get _min_reward()
{
return 0;
}

float simple_env::get _max_reward()
{
return 8.66;
}

tdagent.H
----------------
#ifndef TDGAENT_H
#define TDAGENT_H

#include "critic.H"
#include "actor.H"
#include "simple_env .H"

class tdagent
{

private:

ublas::vector<f loat> get_state();
ublas::vector<f loat> get_previous_st ate();
void set_previous_st ate(ublas::vect or<float> curr_state);
float get_reward();
simple_env* env;
critic* critic1;
actor* actor1;
float d;
state x;

public:
tdagent(simple_ env* environment);
~tdagent();
std::vector<flo at> find_next_actio n();
};

#endif

tdagent.C
-----------------
#include "tdagent.H"

tdagent::tdagen t(simple_env* env)
: critic1(new critic(env->get_cov(),en v->get_state()) ),
actor1(new actor(env->get_cov(),en v->get_state(),
env->get_actions_nu m(),
env->get_min_reward (),env->get_max_reward ()))
{
x.prev=get_stat e();
}

....

Thanks.
Dvir

Jun 7 '06 #3

"dvir" <sc*****@gmail. com> wrote in message
news:11******** **************@ c74g2000cwc.goo glegroups.com.. .

Ok here is a more complete version of the code.
hope its more clear now.

main.C
------------
#include "tdagent.H"
#include "simple_env .H"
#include <vector>

int main()
{
simple_env *env;
env = new simple_env();
env->create();
tdagent *agent;
agent = new tdagent(env);
...
}
1) Why are you dynamically creating these instances? Does that play into a
role in duplicating the problem?

And please remove the "..." as explained in the FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
#include "tdagent.H"
#include "simple_env .H"
#include <vector>

int main()
{
simple_env env;
env.create();
tdagent agent(&env);
}

Is the above enough to duplicate the problem (that is if the rest of the
code is OK, which it isn't -- see next item).

2) vector<float> initial_state(3 );
for (unsigned int i = 0; i < initial_state.s ize (); ++ i)
initial_state (i) = 0; // This should have never compiled
There is no user-defined operator() for vector, but you're calling one.
What does this line do?

initial_state (i) = 0;

Shouldn't this be:

initial_state[i] = 0;

?
The code compiled fine.


It did? That's shocking, seeing the error you made in your program
concerning using ( ) instead of [ ] when accessing elements of the vector.

Here it is to you, as a reference to what I'm speaking of:

#include <vector>
int main()
{
std::vector<flo at> initial_state(3 );
for (unsigned int i = 0; i < initial_state.s ize(); ++i )
initial_state(i ) = 0;
}

----------------------------------------------------------------------------
----------------------------------
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATI ON_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest .c", line 7: error: call of an object of a class type without
appropriate operator() or conversion functions to
pointer-to-function type
initial_state(i ) = 0;
^

1 error detected in the compilation of "ComeauTest .c".
----------------------------------------------------------------------------
------

If the compiler did compile the code you posted, no wonder it core dumped.

You also make the same mistake in other parts of the program, and that is
using ( ) instead of [ ] when accessing or setting elements of the vector.

Paul
Jun 7 '06 #4

Paul wrote:
2)
vector<float> initial_state(3 );
for (unsigned int i = 0; i < initial_state.s ize (); ++ i)
initial_state (i) = 0; // This should have never compiled


There is no user-defined operator() for vector, but you're calling one.
What does this line do?

initial_state (i) = 0;

Shouldn't this be:

initial_state[i] = 0;


I used boost::numeric: :ublas::vector from the boost library
(www.boost.org)
Because I'm using linear algebra functions.
With ublas::vector It's right to write:
vec(i)=0;
Therefore, it did compile fine.
My runing error was while trying to do:
agent = new tdagent(env);
I still don't understand what is wrong with that line.

Thanks,
Dvir

Jun 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1856
by: Alex | last post by:
I am trying to write an Exit module for the Certification server in VB.NET and I cant get the module to be recognised by the Certification MMC snap in. Its function is to capture Serial Numbers of newly created certificates. This is quite obscure and I cant really find any example code. On the face of it it looks pretty straightforward. I have created a Class Library and created a class called Exit as this is suggested for VB, tho I...
6
1741
by: Baloff | last post by:
Hello I wrote a code which is suppose to read a file which contains lines of double and prints it out. thanks for helping double.txt*************************************** 1.01 2.0301
1
4669
by: Tony Johansson | last post by:
Hello experts! As this program is now it's works perfectly when running as a application or as an Applet. Now to my question if I just change this row "public class Converter extends Applet " in class Converter below that it extends from a Frame instead from an Applet then the whole program krasch with message "An exception 'java.lang.IllegalArgumentException' has occured in ... I mean that if I run this program as an application I...
2
5185
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then sends the message "Ping" to the server, which reads it and answers with a "Pong". The game is really simple and the coding should be also very simple! But for me it isn't. By the way, the program uses datagram sockets (UDP). And, I'm using
10
7662
by: ycg0771 | last post by:
I'm trying to modify the following program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. It seems that the more I read into this, the more confused I get. Any help will be greatly apreciated. Here is my latest code... // Payroll program that...
5
11626
by: jbailey006 | last post by:
I am trying to add the following information to a payroll program I am working on for assignment. Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate. Her's what I...
6
5437
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class but when I compile the program I get 13 errors. Can anyone assist me with this? Thank you! Errors I get: C:\Java>javac *.java Payroll3.java:18: illegal start of type while ( !exit ) ^ Payroll3.java:18: <identifier>...
4
2312
nexcompac
by: nexcompac | last post by:
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder. Still getting used to the whole java world and I am trying to compile a program using TextPad. Here is what I have so far. /* * Main.java * * Created on July 19, 2007, 5:54 PM *
9
2918
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading the text files from the watched folder line by line into variables and then posting them to a SQL table. All of the code for the form is shown below. And it works fine except for 2 issues. First issue: In the Finally of the Try for teh SQL...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.