<commit_before>/*******************************************************************************
 Infomap software package for multi-level network clustering
 Copyright (c) 2013, 2014 <NAME>, <NAME>, <NAME>

 This file is part of the Infomap software package.
 See file LICENSE_AGPLv3.txt for full license details.
 For more information, see <http://www.mapequation.org>
 ******************************************************************************/

#ifndef NETWORK_H_
#define NETWORK_H_

#include "Config.h"
#include "../core/StateNetwork.h"

#include <string>
#include <map>
#include <utility>
#include <vector>
#include <set>
#include <utility>
#include <limits>
#include <sstream>
#include <locale>

namespace infomap {

struct LayerNode;

class Network : public StateNetwork {
private:
  // Helpers
  std::istringstream m_extractor;

  // Multilayer
  std::map<unsigned int, Network> m_networks; // intra-layer links
  std::map<LayerNode, std::map<unsigned int, double>> m_interLinks;
  // { layer -> { physId -> stateId }}
  std::map<unsigned int, std::map<unsigned int, unsigned int>> m_layerNodeToStateId;
  std::map<unsigned int, std::map<unsigned int, double>> m_sumIntraOutWeight;
  std::set<unsigned int> m_layers;
  unsigned int m_numInterLayerLinks = 0;
  unsigned int m_numIntraLayerLinks = 0;
  unsigned int m_maxNodeIdInIntraLayerNetworks = 0;

  unsigned int m_multilayerStateIdBitShift = 0;

  // Meta data
  std::map<unsigned int, std::vector<int>> m_metaData;
  unsigned int m_numMetaDataColumns = 0;

  using InsensitiveStringSet = std::set<std::string, io::InsensitiveCompare>;

  std::map<std::string, InsensitiveStringSet> m_ignoreHeadings;
  std::map<std::string, InsensitiveStringSet> m_validHeadings; // {
  // 	{ "pajek", {"*Vertices", "*Edges", "*Arcs"} },
  // 	{ "link-list", {"*Links"} },
  // 	{ "bipartite", {"*Vertices", "*Bipartite"} },
  // 	{ "general", {"*Vertices", "*States", "*Edges", "*Arcs", "*Links", "*Context"} }
  // };

public:
  Network() : StateNetwork() { init(); }
  explicit Network(const Config& config) : StateNetwork(config) { init(); }
  explicit Network(std::string flags) : StateNetwork(Config(std::move(flags))) { init(); }
  virtual ~Network() = default;

  Network(const Network&) = delete;
  Network& operator=(const Network&) = delete;
  Network(Network&&) = delete;
  Network& operator=(Network&&) = delete;

  virtual void clear();

  /**
   * Parse network data from file and generate network
   * @param filename input network
   * @param accumulate add to possibly existing network data (default), else clear before.
   */
  virtual void readInputData(std::string filename = "", bool accumulate = true);

  /**
   * Init categorical meta data on all nodes from a file with the following format:
   * # nodeId metaData<commit_msg>refactor: Don't pass Network string constructor by value<commit_after>/*******************************************************************************
 Infomap software package for multi-level network clustering
 Copyright (c) 2013, 2014 <NAME>, <NAME>, <NAME>

 This file is part of the Infomap software package.
 See file LICENSE_AGPLv3.txt for full license details.
 For more information, see <http://www.mapequation.org>
 ******************************************************************************/

#ifndef NETWORK_H_
#define NETWORK_H_

#include "Config.h"
#include "../core/StateNetwork.h"

#include <string>
#include <map>
#include <utility>
#include <vector>
#include <set>
#include <utility>
#include <limits>
#include <sstream>
#include <locale>

namespace infomap {

struct LayerNode;

class Network : public StateNetwork {
private:
  // Helpers
  std::istringstream m_extractor;

  // Multilayer
  std::map<unsigned int, Network> m_networks; // intra-layer links
  std::map<LayerNode, std::map<unsigned int, double>> m_interLinks;
  // { layer -> { physId -> stateId }}
  std::map<unsigned int, std::map<unsigned int, unsigned int>> m_layerNodeToStateId;
  std::map<unsigned int, std::map<unsigned int, double>> m_sumIntraOutWeight;
  std::set<unsigned int> m_layers;
  unsigned int m_numInterLayerLinks = 0;
  unsigned int m_numIntraLayerLinks = 0;
  unsigned int m_maxNodeIdInIntraLayerNetworks = 0;

  unsigned int m_multilayerStateIdBitShift = 0;

  // Meta data
  std::map<unsigned int, std::vector<int>> m_metaData;
  unsigned int m_numMetaDataColumns = 0;

  using InsensitiveStringSet = std::set<std::string, io::InsensitiveCompare>;

  std::map<std::string, InsensitiveStringSet> m_ignoreHeadings;
  std::map<std::string, InsensitiveStringSet> m_validHeadings; // {
  // 	{ "pajek", {"*Vertices", "*Edges", "*Arcs"} },
  // 	{ "link-list", {"*Links"} },
  // 	{ "bipartite", {"*Vertices", "*Bipartite"} },
  // 	{ "general", {"*Vertices", "*States", "*Edges", "*Arcs", "*Links", "*Context"} }
  // };

public:
  Network() : StateNetwork() { init(); }
  explicit Network(const Config& config) : StateNetwork(config) { init(); }
  explicit Network(const std::string& flags) : StateNetwork(Config(flags)) { init(); }
  ~Network() override = default;

  Network(const Network&) = delete;
  Network& operator=(const Network&) = delete;
  Network(Network&&) = delete;
  Network& operator=(Network&&) = delete;

  void clear() override;

  /**
   * Parse network data from file and generate network
   * @param filename input network
   * @param accumulate add to possibly existing network data (default), else clear before.
   */
  virtual void readInputData(std::string filename = "", bool accumulate = true);

  /**
   * Init categorical meta data on all nodes from a file with the following format:
   * # nodeId metaData
{'fraction_non_alphanumeric': 0.19114260407440212, 'fraction_numerical': 0.0049601417183348095, 'mean_word_length': 5.064446831364124, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '868374', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1685, 'n_words': 481}