R/tempnetwork.R

Defines functions tempnetwork

Documented in tempnetwork

#' A 'tempnetwork' object is primarily composed out of the components, a 'tempflow'-object, a named list containing 'igraph'-object and a named list of named lists which we shall call equivalence-relation.
#'
#' @param tempFlow This parameter expects either a 'tempflow'-object or an 'igraph'-object satisfying all conditions required to construct a 'tempflow'-object.
#' @param graphList This parameter expects a named list of graphs, where
#' the indices are identical to the names of the points in the 'tempflow'-object, i.e. names(graphList)==names(tP(tempFlow));
#' the all vertex-sets have the same size, i.e. forall g,g' in graphList |V(g)|==|V(g')|;
#' the all vertex-sets must be identical if the parameter equivalenceRelation is NULL, i.e. equivalenceRelation == NULL => forall g,g' in graphList: V(g)==V(g').
#' @param tempFlow This parameter expects either a non-empty 'tempflow'-object or an non-empty 'igraph'-object satisfying all conditions required to construct a 'tempflow'-object.
#' @param graphList This parameter expects a non-empty, named list of graphs, where
#' the indices are identical to the names of the points in the 'tempflow'-object, i.e. names(graphList)==names(tP(tempFlow));
#' all vertex-sets have the same size, i.e. forall g,g' in graphList |V(g)|==|V(g')|;
#' every vertex must have a string as name (it must be unique with respect to its own graph);
#' all vertex-sets must be identical if the parameter equivalenceRelation is NULL, i.e. equivalenceRelation == NULL => forall g,g' in graphList: V(g)==V(g').
#' @param equivalenceRelation If NULL, it is expected that the vertex sets of all graphs in the given graph-list are identical, i.e. equivalenceRelation == NULL => forall g,g' in graphList V(g)==V(g').
#' Otherwise, a named list of named lists (let them be called equivalence-classes) is expected, where
#' #' \itemize{
#'   \item the indices of the whole equivalence-relation must be unique, i.e. unique(name(equivalenceRelation))==name(equivalenceRelation) ;
#'   \item  the number of equivalence-classes must be equal to the number of vertices in any graph of the graph list, i.e. forall g in graphList : |equivalenceRelation| == |V(g)|;
#'   \item the indices of each equivalence-class are identical to the names of the points in the 'tempflow'-object, i.e. forall e in equivalenceRelation: names(e)==names(tP(tempFlow));
#'   \item  for every vertex V of the graph indexed by P in the given graph-list, there exists equivalence-class in the equivalence-relation of the given 'tempnetwork'-object that has the value V at index P,
#' i.e. forall p in names(graphList) forall v in V(graphList[p]) exists e in equivalenceRelation: e[p]==v;
#'   \item  for every point P in the "tempflow"-object if one aggregates all entries indexed by point P over all equivalence classes one obtains the vertex set of the graph indexed by P in the given graph-list, i.e.
#' forall p in tF(tempNetwork):  { v | forall e in equivalenceRelation v = e[p]} == V(graphList[p]);
#'   \item for every point P in the "tempflow"-object, every entry indexed by point P over all equivalence classes must be unique, i.e.
#' forall p in tF(tempNetwork) forall e,e' in equivalenceRelation: e!=e' => e[p]!=e'[p];
#' }
#'
#' @param setDefaultGraphNames If TRUE any graph in the given graph-list containing a vertex without a name, will be replaced by a graph where the name of each
#' vertex is a string corresponding to its index in the respective 'igraph'-object. Moreover, any graph containing a vertex with a name that is not a string, will be
#' coerced into a string.
#'
#' @param setDefaultFlowValues If TRUE, any invalid weight or name assignment will be replaced by its corresponding default assignments.
#' \itemize{
#'   \item Under the default weight assignment, the weight of a loop-edge is 0 and of a non-loop-edge is 1.
#'   \item Under the default name assignment, the name of a vertex is its current vertex-id (as assigned within the igraph package) as a string.
#' }
#' @param storeTempGraph A flag indicating whether the graph representation of the 'tempnetwork'-object, let it be called tempgraph, should be stored if computed.
#' @param safe If TRUE, all tempnetwork and tempflow requirements specified above will be checked.
tempnetwork <- function(tempFlow, graphList, equivalenceRelation = NULL, setDefaultGraphNames = TRUE, setDefaultFlowValues = FALSE, storeTempGraph = FALSE ,safe = TRUE){
  if (class(tempFlow) == "igraph") {tempFlow <- tempflow(tempFlow, setDefaultValues = setDefaultFlowValues, safe = safe)}
  if (class(tempFlow) != "tempflow") { error_not_tempflow() }
  graphList <- graphlist_cleaner(graphList, setDefaultGraphNames)
  tempNetwork <- structure(list("tempFlow" = tempFlow, "graphList" = graphList, "equivRel" = equivalenceRelation, "tempGraph" = NULL, "storeTempGraph" = storeTempGraph), class = "tempnetwork")
  if (safe) {check_tempnetwork_completely(tempNetwork)}
  return(tempNetwork)
}
KonstantinRK/tempnetwork documentation built on Dec. 23, 2019, 6:40 p.m.