craam/modeltools.hpp
void to_csv(const RMDP& rmdp, ostream& output, bool header = true) {

    //write header if so requested
    if(header){
        output << "idstatefrom," << "idaction," <<
            "idoutcome," << "idstateto," << "probability," << "reward" << endl;
    }

    //idstatefrom
    for(size_t i = 0l; i < rmdp.get_states().size(); i++){
        const auto& actions = rmdp.get_state(i).get_actions();
        //idaction
        for(size_t j = 0; j < actions.size(); j++){

            const auto& outcomes = actions[j].get_outcomes();
            //idoutcome
            for(size_t k = 0; k < outcomes.size(); k++){
                const auto& tran = outcomes[k];

                auto& indices = tran.get_indices();
                const auto& rewards = tran.get_rewards();
                const auto& probabilities = tran.get_probabilities();
                //idstateto
                for (size_t l = 0; l < tran.size(); l++){
                    output << i << ',' << j << ',' << k << ',' << indices[l] << ','
                            << probabilities[l] << ',' << rewards[l] << endl;
                }
            }
        }
    }
}
/**
Saves the RMDP model to a stream as a simple csv file. States, actions, and outcomes
are identified by 0-based ids. Columns are separated by commas, and rows by new lines.

The file is formatted with the following columns:
idstatefrom, idaction, idoutcome, idstateto, probability, reward

Exported and imported MDP will be be slightly different. Since action/transitions
will not be exported if there are no actions for the state. However, when
there is data for action 1 and action 3, action 2 will be created with no outcomes.

Note that underlying nominal distributions are not saved.

\param output Output for the stream
\param header Whether the header should be written as the
      first line of the file represents the header.
*/
Saves the RMDP model to a stream as a simple csv file. States, actions, and outcomes
are identified by 0-based ids. Columns are separated by commas, and rows by new lines.

The file is formatted with the following columns:
idstatefrom, idaction, idoutcome, idstateto, probability, reward

Exported and imported MDP will be be slightly different. Since action/transitions
will not be exported if there are no actions for the state. However, when
there is data for action 1 and action 3, action 2 will be created with no outcomes.

Note that underlying nominal distributions are not saved.

\param output Output for the stream
\param header Whether the header should be written as the
first line of the file represents the header.
Saves the RMDP model to a stream as a simple csv file . States actions and outcomes are identified by 0 - based ids . Columns are separated by commas and rows by new lines . The file is formatted with the following columns : idstatefrom idaction idoutcome idstateto probability reward Exported and imported MDP will be be slightly different . Since action / transitions will not be exported if there are no actions for the state . However when there is data for action 1 and action 3 action 2 will be created with no outcomes . Note that underlying nominal distributions are not saved . \ param output Output for the stream \ param header Whether the header should be written as the first line of the file represents the header .
void to_csv(const RMDP& rmdp, ostream& output, bool header = true) {
    if(header){
        output << "idstatefrom," << "idaction," <<
            "idoutcome," << "idstateto," << "probability," << "reward" << endl;
    }
    for(size_t i = 0l; i < rmdp.get_states().size(); i++){
        const auto& actions = rmdp.get_state(i).get_actions();
        for(size_t j = 0; j < actions.size(); j++){
            const auto& outcomes = actions[j].get_outcomes();
            for(size_t k = 0; k < outcomes.size(); k++){
                const auto& tran = outcomes[k];
                auto& indices = tran.get_indices();
                const auto& rewards = tran.get_rewards();
                const auto& probabilities = tran.get_probabilities();
                for (size_t l = 0; l < tran.size(); l++){
                    output << i << ',' << j << ',' << k << ',' << indices[l] << ','
                            << probabilities[l] << ',' << rewards[l] << endl;
                }
            }
        }
    }
}
void to_csv ( const RMDP & rmdp , ostream & output , bool header = true ) { if ( header ) { output << " " << " " << " " << " " << " " << " " << endl ; } for ( size_t i = 0l ; i < rmdp . get_states ( ) . size ( ) ; i ++ ) { const auto & actions = rmdp . get_state ( i ) . get_actions ( ) ; for ( size_t j = 0 ; j < actions . size ( ) ; j ++ ) { const auto & outcomes = actions [ j ] . get_outcomes ( ) ; for ( size_t k = 0 ; k < outcomes . size ( ) ; k ++ ) { const auto & tran = outcomes [ k ] ; auto & indices = tran . get_indices ( ) ; const auto & rewards = tran . get_rewards ( ) ; const auto & probabilities = tran . get_probabilities ( ) ; for ( size_t l = 0 ; l < tran . size ( ) ; l ++ ) { output << i << ' ' << j << ' ' << k << ' ' << indices [ l ] << ' ' << probabilities [ l ] << ' ' << rewards [ l ] << endl ; } } } } }
Saves the RMDP model to a stream as a simple csv file.
Saves the RMDP model to a stream as a simple csv file .
//write header if so requested //idstatefrom //idaction //idoutcome //idstateto