[erlang-questions] Beginner questions

Gene Sher corticalcomputer@REDACTED
Mon Dec 24 18:16:51 CET 2012


Hello all,

The problem is not with the code, but that population_monitor should not be
started with start(). Population_monitor should be started with the
properly set up constraints. To use the default constraints you start with
population_monitor:test().
test()->
    init_population(#state{op_mode = [gt,benchmark]},?INIT_CONSTRAINTS).
%The test/0 function starts the population monitor through
init_population/1 with a set of default parameters specified by the macros
of this module.

prep_PopState(PMP,Specie_Constraints)->
    S=#state{
        op_mode=PMP#pmp.op_mode,
        population_id = PMP#pmp.population_id,
        survival_percentage=PMP#pmp.survival_percentage,
        specie_size_limit=PMP#pmp.specie_size_limit,
        init_specie_size=PMP#pmp.init_specie_size,
        polis_id=PMP#pmp.polis_id,
        generation_limit=PMP#pmp.generation_limit,
        evaluations_limit=PMP#pmp.evaluations_limit,
        fitness_goal=PMP#pmp.fitness_goal,
        benchmarker_pid=PMP#pmp.benchmarker_pid
    },
    init_population(S,Specie_Constraints).

init_population(Init_State,Specie_Constraints)->
    random:seed(now()),
    Population_Id = Init_State#state.population_id,
    %OpMode = Init_State#state.op_mode,
    F = fun()->
        case genotype:read({population,Population_Id}) of
            undefined ->

create_Population(Population_Id,Init_State#state.init_specie_size,Specie_Constraints);
            _ ->
                delete_population(Population_Id),

create_Population(Population_Id,Init_State#state.init_specie_size,Specie_Constraints)
        end
    end,
    Result = mnesia:transaction(F),
    case Result of
        {atomic,_} ->
            population_monitor:start(Init_State);
        Error ->
            io:format("******** ERROR in PopulationMonitor:~p~n",[Error])
    end.
%The function init_population/1 creates a new population with the id
Population_Id, composed of length(Specie_Constraints) species, where each
specie uses the particular specie constraint specified within the
Specie_Constraints list. The function first checks if a population with the
noted Population_Id already exists, if a population does exist, then the
function first delets it, and then creates a fresh one. Since the ids are
usually generated with the genotype:create_UniqueId/0, the only way an
already existing Population_Id is dropped into the function as a parameter
is if it is intended, usually when runing tests, with the Population_Id =
test.

You will note that population_monitor;start(Init_state) is the only way to
properly start the population monitor. I did not wish to remove the
function population_monitor:start() from the module, for the sake of future
extensions. But there are no problems with the code.

Best regards,
-Gene

On Mon, Dec 24, 2012 at 4:35 AM, OJ Reeves <oj@REDACTED> wrote:

> All,
>
> The first issue is that the init() function isn't correct for this
> gen_server.
>
> On line 83, the init function starts like this:
> init(S) ->
> When it should (apparently) be like this:
> init([S]) ->
>
> This doesn't make the server run though. The next error states:
>
> 6> population_monitor:start().
> ******** Population monitor started with parameters:{state,
>                                                      [gt],
>                                                      test,[],[],undefined,
>
>  undefined,undefined,[],0,
>                                                      0,0,0,0,undefined,
>                                                      undefined,undefined,
>                                                      undefined,undefined,
>                                                      undefined,0.5,10,10,
>
>  mathema,100,100000,inf,
>                                                      undefined,false}
> {error,{{badrecord,population},
>         [{population_monitor,extract_AgentIds,2,
>                              [{file,"population_monitor.erl"},{line,372}]},
>          {population_monitor,init,1,
>                              [{file,"population_monitor.erl"},{line,89}]},
>          {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
>          {proc_lib,init_p_do_apply,3,
>                    [{file,"proc_lib.erl"},{line,227}]}]}}
>
> I get the feeling that there's going to be more stuff requiring fixes as
> you go. Perhaps the best thing its to get in touch with the author directly
> and find out about the state of the source base before continuing.
>
> Cheers
> OJ
>
>
> On Mon, Dec 24, 2012 at 5:49 PM, Ivan Uemlianin <ivan@REDACTED> wrote:
>
>> Dear Bob
>>
>> This line should be part of the function population_monitor:init/1
>> (that's file population_monitor, function init, which takes one argument).
>>
>> The error it complains of is {badrecord,state}, so perhaps the record S
>> has been badly set up.
>>
>> Are you learning erlang through neuroevolution :) ?  Do you have other
>> reference resources?
>>
>> Nadolig Llawen
>>
>> Ivan
>>
>>
>> --
>> festina lente
>>
>>
>> On 24 Dec 2012, at 07:24, Bob Matthews <rgmatthews@REDACTED> wrote:
>>
>> Thank you Ivan
>>
>> line 82: Population_Id = S#state.population_id,
>>
>> Merry Xmas to you too :)
>>
>> Bob
>> Dunedin
>> New Zealand
>>
>> On 24/12/2012 8:14 p.m., Ivan Uemlianin wrote:
>>
>> I dont have my computer with me but the error is at line 82 of the file
>> population_monitor.erl.
>>
>>  Best wishes
>>
>>  Ivan
>>
>> --
>> festina lente
>>
>>
>> On 24 Dec 2012, at 01:32, Bob Matthews <rgmatthews@REDACTED> wrote:
>>
>>   The code that I am looking at is DXNN2 copyrighted to Gene Sher.
>>
>> The error message I got which I am having difficulty interpreting is as
>> follows....................
>>
>> 4> population_monitor:start().
>> {error,{{badrecord,state},
>>         [{population_monitor,init,1,
>>                              [{file,"population_monitor.erl"},{line,82}]},
>>          {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
>>          {proc_lib,init_p_do_apply,3,
>>                    [{file,"proc_lib.erl"},{line,227}]}]}}
>>
>> I am using the latest versionR15B03
>>
>> Thank you for you help
>>
>> Bob
>> Dunedin New Zealand
>>
>> On 24/12/2012 11:58 a.m., Matti Oinas wrote:
>>
>> Hi,
>>
>> My first proposal is to change the editor to something more usable like
>> emacs or if you prefer something different then notepad++, sublime text or
>> eclipse + erlIDE. Everyone of these are able to show you the line numbers
>> and offer syntax highlight features.
>>
>> It would help a lot if you tell us which code you are looking at. Server
>> callbacks probably mean gen_server callbacks so it doesn't matter if you
>> are using windows or linux.
>>
>> Matti
>>
>> On 12/24/2012 12:08 AM, Bob Matthews wrote:
>>
>> Hi
>>
>> I have just started to learn Erlang............
>> I am using Windows 7 on a PC
>>
>> *Question 1*)  when I get an error message, what is the easiest way for
>> me to find the exact line number?
>> I use ms Word as an editor.
>>
>> *Question 2*) the code I am looking at was run on Unix, on a server.
>> Part of the code talks about server call-backs etc.
>> It is unclear how I translate that to a windows PC
>>
>> Many thanks
>>
>> Bob
>>
>>
>> _______________________________________________
>> erlang-questions mailing listerlang-questions@REDACTED://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>> No virus found in this message.
>> Checked by AVG - www.avg.com
>> Version: 2013.0.2805 / Virus Database: 2634/5951 - Release Date: 12/11/12
>> Internal Virus Database is out of date.
>>
>>
>>   _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>> No virus found in this message.
>> Checked by AVG - www.avg.com
>> Version: 2013.0.2805 / Virus Database: 2634/5951 - Release Date: 12/11/12
>> Internal Virus Database is out of date.
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>
> --
>
> OJ Reeves
> +61 431 952 586
> http://buffered.io/
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121224/f74fd2d3/attachment.htm>


More information about the erlang-questions mailing list