[Rsiena-commits] r238 - in pkg/RSienaTest/src/network: . iterators layers
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 5 11:46:39 CEST 2013
Author: ortmann
Date: 2013-08-05 11:46:39 +0200 (Mon, 05 Aug 2013)
New Revision: 238
Modified:
pkg/RSienaTest/src/network/INetworkChangeListener.h
pkg/RSienaTest/src/network/Network.cpp
pkg/RSienaTest/src/network/OneModeNetwork.cpp
pkg/RSienaTest/src/network/iterators/CombinedTieIterator.cpp
pkg/RSienaTest/src/network/iterators/CombinedTieIterator.h
pkg/RSienaTest/src/network/iterators/ITieIterator.h
pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.cpp
pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.h
pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.cpp
pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.h
pkg/RSienaTest/src/network/iterators/UnionTieIterator.cpp
pkg/RSienaTest/src/network/iterators/UnionTieIterator.h
pkg/RSienaTest/src/network/layers/DistanceTwoLayer.cpp
pkg/RSienaTest/src/network/layers/DistanceTwoLayer.h
pkg/RSienaTest/src/network/layers/NetworkLayer.h
Log:
added:
Documentation
changes:
modified visibilities of ITieIterators
Modified: pkg/RSienaTest/src/network/INetworkChangeListener.h
===================================================================
--- pkg/RSienaTest/src/network/INetworkChangeListener.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/INetworkChangeListener.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -3,11 +3,11 @@
*
* Web: http://www.stats.ox.ac.uk/~snijders/siena/
*
- * File: NetworkChangeListener.h
+ * File: INetworkChangeListener.h
*
* Description: This module defines the interface INetworkChangeListener.
* Any class implementing this interface can be added to a network and gets
- * informed once an edge is introduced/withdrawn from the network.
+ * informed about network changes (tie introduction/withdrawal or clearing).
*****************************************************************************/
#ifndef INETWORKCHANGELISTENER_H_
@@ -17,19 +17,45 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: INetworkChangeListener interface
+// ----------------------------------------------------------------------------
+
class INetworkChangeListener {
public:
+
+ /**
+ * Destructor.
+ */
virtual ~INetworkChangeListener() {
}
+
+ /**
+ * Invoked when an tie is introduced to the network.
+ */
virtual void onTieIntroductionEvent(const Network& rNetwork, const int ego,
const int alter) = 0;
+
+ /**
+ * Invoked when an tie is withdrawn from the network.
+ */
virtual void onTieWithdrawalEvent(const Network& rNetwork, const int ego,
const int alter) = 0;
+
+ /**
+ * Invoked when the network is cleared.
+ */
virtual void onNetworkClearEvent(const Network& rNetwork) = 0;
+
protected:
+
+ /**
+ * Constructor.
+ */
INetworkChangeListener() {
}
private:
+
// disable copy constructor and copy assignment
INetworkChangeListener(const INetworkChangeListener& rhs);
INetworkChangeListener& operator=(const INetworkChangeListener& rhs);
Modified: pkg/RSienaTest/src/network/Network.cpp
===================================================================
--- pkg/RSienaTest/src/network/Network.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/Network.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -591,6 +591,11 @@
}
}
+/**
+ * Tells whether the network is a one mode network or not.
+ * @return <code>True</code> if the network is a one mode network,
+ * <code>False</code> otherwise.
+ */
bool Network::isOneMode() const {
return false;
}
Modified: pkg/RSienaTest/src/network/OneModeNetwork.cpp
===================================================================
--- pkg/RSienaTest/src/network/OneModeNetwork.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/OneModeNetwork.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -442,6 +442,9 @@
}
}
+/**
+ * @copydoc Network::isOneMode()
+ */
bool OneModeNetwork::isOneMode() const {
return true;
}
Modified: pkg/RSienaTest/src/network/iterators/CombinedTieIterator.cpp
===================================================================
--- pkg/RSienaTest/src/network/iterators/CombinedTieIterator.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/CombinedTieIterator.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,14 +1,22 @@
-/*
- * CombinedTieIterator.cpp
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 30.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: CombinedTieIterator.cpp
+ *
+ * Description: This abstract iterator allows to combine two ITieIterators.
+ *****************************************************************************/
#include "CombinedTieIterator.h"
namespace siena {
+/**
+ * Constructor cloning the both input iterators.
+ * @param[in] iter1 The first iterator.
+ * @param[in] iter2 The second iterator.
+ */
CombinedTieIterator::CombinedTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2) :
ITieIterator(), //
@@ -16,11 +24,17 @@
lpIter2(iter2.clone()) {
}
+/**
+ * Destructor.
+ */
CombinedTieIterator::~CombinedTieIterator() {
delete lpIter1;
delete lpIter2;
}
+/**
+ * Copy Constructor.
+ */
CombinedTieIterator::CombinedTieIterator(const CombinedTieIterator& rhs) :
ITieIterator(rhs), //
lpIter1(rhs.lpIter1->clone()), //
Modified: pkg/RSienaTest/src/network/iterators/CombinedTieIterator.h
===================================================================
--- pkg/RSienaTest/src/network/iterators/CombinedTieIterator.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/CombinedTieIterator.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,12 @@
-/*
- * CombinedTieIterator.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 25.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: CombinedTieIterator.h
+ *
+ * Description: This abstract iterator allows to combine two ITieIterators.
+ *****************************************************************************/
#ifndef COMBINEDTIEITERATOR_H_
#define COMBINEDTIEITERATOR_H_
@@ -12,22 +15,45 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: CombinedTieIterator abstract class
+// ----------------------------------------------------------------------------
+
class CombinedTieIterator: public ITieIterator {
public:
+
virtual ~CombinedTieIterator();
protected:
+
CombinedTieIterator(const ITieIterator& iter1, const ITieIterator& iter2);
+
CombinedTieIterator(const CombinedTieIterator& rhs);
+ /**
+ * Tells whether both iterators point to the same actor.
+ * @return <code>True</code> if both iterators point to the same
+ * actor and <code>False</code> otherwise.
+ */
inline bool isCommon() const {
return lpIter1->actor() == lpIter2->actor();
}
protected:
+
+ /**
+ * The first iterator.
+ */
ITieIterator* const lpIter1;
+
+ /**
+ * The second iterator.
+ */
ITieIterator* const lpIter2;
+
private:
+
+ /// Disable assignment operator.
CombinedTieIterator& operator=(const CombinedTieIterator&);
};
Modified: pkg/RSienaTest/src/network/iterators/ITieIterator.h
===================================================================
--- pkg/RSienaTest/src/network/iterators/ITieIterator.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/ITieIterator.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,13 @@
-/*
- * ITieIterator.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 16.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: ITieIterator.h
+ *
+ * Description: This interface defines the common operations supported by
+ * any TieIterator.
+ *****************************************************************************/
#ifndef ITIEITERATOR_H_
#define ITIEITERATOR_H_
@@ -12,21 +16,60 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: ITieIterator interface
+// ----------------------------------------------------------------------------
+
class ITieIterator {
public:
+
+ /**
+ * Destructor.
+ */
virtual ~ITieIterator() {
}
+
+ /**
+ * Moves the iterator to the next position.
+ */
virtual void next() = 0;
+
+ /**
+ * Returns the actor at the current position. Note that the
+ * behavior of this function is undefined if the iterator is
+ * invalid.
+ * @return The actor at the current position.
+ */
virtual int actor() const = 0;
+
+ /**
+ * Tells whether the current position is valid or not.
+ * @return <code>True</code> indicating that the current position
+ * is valid and <code>False</code> otherwise.
+ */
virtual bool valid() const = 0;
+
+ /**
+ * Creates an identical copy of the iterator.
+ */
virtual ITieIterator* clone() const = 0;
protected:
+
+ /**
+ * Constructor.
+ */
ITieIterator() {
}
+ /**
+ * Copy assignment Constructor.
+ */
ITieIterator(const ITieIterator&) {
}
+ /**
+ * Assignment operator.
+ */
ITieIterator& operator=(const ITieIterator&) {
return *this;
}
Modified: pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.cpp
===================================================================
--- pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,14 +1,22 @@
-/*
- * IntersectionTieIterator.cpp
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 30.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: IntersectionTieIterator.cpp
+ *
+ * Description: This module defines an iterator that only accesses the
+ * intersection of two iterators.
+ *****************************************************************************/
#include "IntersectionTieIterator.h"
namespace siena {
+/**
+ * @copydoc CombinedTieIterator::CombinedTieIterator()
+ * Constructor.
+ */
IntersectionTieIterator::IntersectionTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2) :
CombinedTieIterator(iter1, iter2) {
@@ -17,9 +25,15 @@
}
}
+/**
+ * @copydoc CombinedTieIterator::~CombinedTieIterator()
+ */
IntersectionTieIterator::~IntersectionTieIterator() {
}
+/**
+ * @copydoc ITieIterator::actor()
+ */
int IntersectionTieIterator::actor() const {
if (valid()) {
return lpIter1->actor();
@@ -27,12 +41,20 @@
throw InvalidIteratorException();
}
+/**
+ * Moves the iterator to the next common actor.
+ * @sa CombinedTieIterator::isCommon()
+ */
void IntersectionTieIterator::next() {
lpIter1->next();
lpIter2->next();
skip();
}
+/**
+ * Moves the iterator until one of them becomes invalid or they
+ * point to the same actor.
+ */
void IntersectionTieIterator::skip() {
while (valid() && !isCommon()) {
while (lpIter1->valid() && lpIter1->actor() < lpIter2->actor()) {
@@ -47,14 +69,23 @@
}
}
+/**
+ * @copydoc ITieIterator::valid()
+ */
bool IntersectionTieIterator::valid() const {
return lpIter1->valid() && lpIter2->valid();
}
+/**
+ * @copydoc ITieIterator::clone()
+ */
IntersectionTieIterator* IntersectionTieIterator::clone() const {
return new IntersectionTieIterator(*this);
}
+/**
+ * Copy Constructor.
+ */
IntersectionTieIterator::IntersectionTieIterator(
const IntersectionTieIterator& rhs) :
CombinedTieIterator(rhs) {
Modified: pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.h
===================================================================
--- pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/IntersectionTieIterator.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,13 @@
-/*
- * IntersectionTieIterator.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 25.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: IntersectionTieIterator.h
+ *
+ * Description: This module defines an iterator that only accesses the
+ * intersection of two iterators.
+ *****************************************************************************/
#ifndef INTERSECTIONTIEITERATOR_H_
#define INTERSECTIONTIEITERATOR_H_
@@ -12,22 +16,35 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: IntersectionTieIterator class
+// ----------------------------------------------------------------------------
+
class IntersectionTieIterator: public CombinedTieIterator {
public:
+
IntersectionTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2);
virtual ~IntersectionTieIterator();
virtual void next();
+
virtual int actor() const;
+
virtual bool valid() const;
+
virtual IntersectionTieIterator * clone() const;
+
void skip();
protected:
+
IntersectionTieIterator(const IntersectionTieIterator& rhs);
+
private:
+
+ /// Disable assignment operator.
IntersectionTieIterator& operator=(const IntersectionTieIterator&);
};
Modified: pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.cpp
===================================================================
--- pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,47 +1,76 @@
-/*
- * SymDiffTieIterator.cpp
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 30.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: SymDiffTieIterator.cpp
+ *
+ * Description: This module defines an iterator that only accesses the
+ * symmetric difference of two iterators.
+ *****************************************************************************/
#include "SymDiffTieIterator.h"
namespace siena {
+/**
+ * @copydoc UnionTieIterator::UnionTieIterator(ITieIterator,ITieIterator)
+ */
SymDiffTieIterator::SymDiffTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2) :
UnionTieIterator(iter1, iter2) {
+ // move the iterator to the first valid position
init();
}
+/**
+ * @copydoc UnionTieIterator::UnionTieIterator(ITieIterator,ITieIterator,int,int)
+ */
SymDiffTieIterator::SymDiffTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2, int idIter1, int idIter2) :
UnionTieIterator(iter1, iter2, idIter1, idIter2) {
+ // move the iterator to the first valid position
init();
}
-SymDiffTieIterator::SymDiffTieIterator(const SymDiffTieIterator& rhs) :
- UnionTieIterator(rhs) {
-}
-
+/**
+ * @copydoc UnionTieIterator::~UnionTieIterator()
+ */
SymDiffTieIterator::~SymDiffTieIterator() {
}
+/**
+ * @copydoc UnionTieIterator::clone()
+ */
SymDiffTieIterator* SymDiffTieIterator::clone() const {
return new SymDiffTieIterator(*this);
}
+/**
+ * Moves the iterator to the next position where both iterators
+ * point to different actors.
+ */
+void SymDiffTieIterator::next() {
+ do {
+ UnionTieIterator::next();
+ } while (lpIter1->valid() && lpIter2->valid() && isCommon());
+}
+
+/**
+ * Copy Constructor.
+ */
+SymDiffTieIterator::SymDiffTieIterator(const SymDiffTieIterator& rhs) :
+ UnionTieIterator(rhs) {
+}
+
+/**
+ * Moves the iterator to the first position where both iterators
+ * point to different actors.
+ */
void SymDiffTieIterator::init() {
if (lpIter1->valid() && lpIter2->valid() && isCommon()) {
next();
}
}
-void SymDiffTieIterator::next() {
- do {
- UnionTieIterator::next();
- } while (lpIter1->valid() && lpIter2->valid() && isCommon());
-}
-
} /* namespace siena */
Modified: pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.h
===================================================================
--- pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/SymDiffTieIterator.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,13 @@
-/*
- * SymDiffTieIterator.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 25.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: SymDiffTieIterator.h
+ *
+ * Description: This module defines an iterator that only accesses the
+ * symmetric difference of two iterators.
+ *****************************************************************************/
#ifndef SYMDIFFTIEITERATOR_H_
#define SYMDIFFTIEITERATOR_H_
@@ -12,18 +16,33 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: SymDiffTieIterator class
+// ----------------------------------------------------------------------------
+
class SymDiffTieIterator: public UnionTieIterator {
+
public:
+
SymDiffTieIterator(const ITieIterator& iter1, const ITieIterator& iter2);
+
SymDiffTieIterator(const ITieIterator& iter1, const ITieIterator& iter2,
int idIter1, int idIter2);
+
virtual ~SymDiffTieIterator();
+
virtual SymDiffTieIterator* clone() const;
+
virtual void next();
+
protected:
+
SymDiffTieIterator(const SymDiffTieIterator& rhs);
+
private:
+
void init();
+
};
} /* namespace siena */
Modified: pkg/RSienaTest/src/network/iterators/UnionTieIterator.cpp
===================================================================
--- pkg/RSienaTest/src/network/iterators/UnionTieIterator.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/UnionTieIterator.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,29 +1,55 @@
-/*
- * UnionTieIterator.cpp
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 30.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: UnionTieIterator.cpp
+ *
+ * Description: This module defines an iterator that only the union
+ * of two iterators.
+ *****************************************************************************/
#include "UnionTieIterator.h"
namespace siena {
+/**
+ * Constructor cloning the both input iterators and additionally
+ * adding identifiers to both iterators
+ * @param[in] iter1 The first iterator.
+ * @param[in] iter2 The second iterator.
+ */
UnionTieIterator::UnionTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2) :
CombinedTieIterator(iter1, iter2) {
+ // adds default id's to the iterators
init(1, 2);
}
+/**
+ * Constructor cloning the both input iterators and additionally
+ * adding the given identifiers to both iterators
+ * @param[in] iter1 The first iterator.
+ * @param[in] iter2 The second iterator.
+ * @param[in] idIter1 The ID of iter1.
+ * @param[in] idIter2 The ID of iter2.
+ */
UnionTieIterator::UnionTieIterator(const ITieIterator& iter1,
const ITieIterator& iter2, int idIter1, int idIter2) :
CombinedTieIterator(iter1, iter2) {
+ // adds the given id's to the iterators
init(idIter1, idIter2);
}
+/**
+ * @copydoc CombinedTieIterator::~CombinedTieIterator()
+ */
UnionTieIterator::~UnionTieIterator() {
}
+/**
+ * @copydoc ITieIterator::next()
+ */
void UnionTieIterator::next() {
// at least one of the iterators has to be valid
if (!valid()) {
@@ -46,6 +72,9 @@
}
}
+/**
+ * @copydoc ITieIterator::actor()
+ */
int UnionTieIterator::actor() const {
// if both iterators are valid return the actor with the lower value
if (lpIter1->valid() && lpIter2->valid()) {
@@ -63,14 +92,26 @@
throw InvalidIteratorException();
}
+/**
+ * @copydoc ITieIterator::valid()
+ */
bool UnionTieIterator::valid() const {
return lpIter1->valid() || lpIter2->valid();
}
+/**
+ * @copydoc ITieIterator::clone()
+ */
UnionTieIterator * UnionTieIterator::clone() const {
return new UnionTieIterator(*this);
}
+/**
+ * Returns the ID of the iterator not adjacent to the current actor.
+ * Note that if the current actor is common this method returns the
+ * ID of the first iterator.
+ * @return The ID of the iterator not adjacent to the current node
+ */
int UnionTieIterator::getInactiveIterID() {
if (valid()) {
if (!lpIter1->valid()) {
@@ -84,6 +125,12 @@
throw InvalidIteratorException();
}
+/**
+ * Returns the ID of the iterator adjacent to the current actor. Note
+ * that if the current actor is common this will always return the
+ * ID of the second iterator.
+ * @return The ID of the iterator adjacent to the current node
+ */
int UnionTieIterator::getActiveIterID() {
if (getInactiveIterID() == lIdIter1) {
return lIdIter2;
@@ -91,16 +138,30 @@
return lIdIter1;
}
+/**
+ * Tells whether the current actor is adjacent to both iterators
+ * or not.
+ * @returns <code>True</code> if both iterators are adjacent to
+ * the current actor, <code>False</code> otherwise.
+ */
bool UnionTieIterator::isCommonNeighbor() const {
return lpIter1->valid() && lpIter2->valid() && isCommon();
}
+/**
+ * Copy Constructor.
+ */
UnionTieIterator::UnionTieIterator(const UnionTieIterator& rhs) :
CombinedTieIterator(rhs), //
lIdIter1(rhs.lIdIter1), //
lIdIter2(rhs.lIdIter2) {
}
+/**
+ * Intializes the ID's of both iterators.
+ * @param[in] idIter1 The ID of the first iterator.
+ * @param[in] idIter2 The ID of the second iterator.
+ */
void UnionTieIterator::init(int idIter1, int idIter2) {
lIdIter1 = idIter1;
lIdIter2 = idIter2;
Modified: pkg/RSienaTest/src/network/iterators/UnionTieIterator.h
===================================================================
--- pkg/RSienaTest/src/network/iterators/UnionTieIterator.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/iterators/UnionTieIterator.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,13 @@
-/*
- * UnionTieIterator.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 25.07.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: UnionTieIterator.h
+ *
+ * Description: This module defines an iterator that only the union
+ * of two iterators.
+ *****************************************************************************/
#ifndef UNIONTIEITERATOR_H_
#define UNIONTIEITERATOR_H_
@@ -12,30 +16,46 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: UnionTieIterator class
+// ----------------------------------------------------------------------------
+
class UnionTieIterator: public CombinedTieIterator {
public:
+
UnionTieIterator(const ITieIterator& iter1, const ITieIterator& iter2);
+
UnionTieIterator(const ITieIterator& iter1, const ITieIterator& iter2,
int idIter1, int idIter2);
+
virtual ~UnionTieIterator();
virtual void next();
+
int actor() const;
+
bool valid() const;
+
virtual UnionTieIterator * clone() const;
int getInactiveIterID();
+
int getActiveIterID();
+
bool isCommonNeighbor() const;
protected:
+
UnionTieIterator(const UnionTieIterator& rhs);
private:
+
int lIdIter1;
+
int lIdIter2;
void init(int idIter1, int idIter2);
+
UnionTieIterator& operator=(const UnionTieIterator&);
};
Modified: pkg/RSienaTest/src/network/layers/DistanceTwoLayer.cpp
===================================================================
--- pkg/RSienaTest/src/network/layers/DistanceTwoLayer.cpp 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/layers/DistanceTwoLayer.cpp 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,13 @@
-/*
- * DistanceTwoLayer.cpp
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 05.08.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: DistanceTwoLayer.cpp
+ *
+ * Description: This module stores for each actor all its neighbors at
+ * distance two with respect to the observed network.
+ *****************************************************************************/
#include "DistanceTwoLayer.h"
@@ -19,20 +23,78 @@
typedef map<int, int> TieMap;
+/**
+ * Constructor.
+ * @param[in] rNetwork The network the layer is based on
+ */
DistanceTwoLayer::DistanceTwoLayer(const Network& rNetwork) :
NetworkLayer(), //
lpAdjacencies(new map<int, int> [rNetwork.n()]) {
+ initialize(rNetwork);
+}
+
+/**
+ * Destructor.
+ */
+DistanceTwoLayer::~DistanceTwoLayer() {
+ delete[] lpAdjacencies;
+}
+
+/**
+ * @copydoc INetworkChangeListener::onTieIntroductionEvent()
+ */
+void DistanceTwoLayer::onTieIntroductionEvent(const Network& rNetwork,
+ const int ego, const int alter) {
if (rNetwork.isOneMode()) {
+ modify2PathCountOneMode(rNetwork, ego, alter, 1);
+ } else {
+ modify2PathCountTwoMode(rNetwork, ego, alter, -1);
+ }
+}
+
+/**
+ * @copydoc INetworkChangeListener::onTieWithdrawalEvent()
+ */
+void DistanceTwoLayer::onTieWithdrawalEvent(const Network& rNetwork,
+ const int ego, const int alter) {
+ if (rNetwork.isOneMode()) {
+ modify2PathCountOneMode(rNetwork, ego, alter, -1);
+ } else {
+ modify2PathCountTwoMode(rNetwork, ego, alter, -1);
+ }
+}
+
+/**
+ * @copydoc INetworkChangeListener::onNetworkClearEvent()
+ */
+void DistanceTwoLayer::onNetworkClearEvent(const Network& rNetwork) {
+ for (int i = 0; i < rNetwork.n(); ++i) {
+ lpAdjacencies[i].clear();
+ }
+}
+
+/**
+ * Returns the actor's neighbors at distance two.
+ */
+IncidentTieIterator DistanceTwoLayer::getDistanceTwoNeighbors(int ego) const {
+ return IncidentTieIterator(lpAdjacencies[ego]);
+}
+
+/**
+ * @copydoc NetworkLayer::initialize()
+ */
+void DistanceTwoLayer::initialize(const Network& rNetwork) {
+ if (rNetwork.isOneMode()) {
initializeOneMode(rNetwork);
} else {
initializeTwoMode(rNetwork);
}
}
-DistanceTwoLayer::~DistanceTwoLayer() {
- delete[] lpAdjacencies;
-}
-
+/**
+ * Initializes the layer given the reference network is a one mode
+ * network.
+ */
void DistanceTwoLayer::initializeOneMode(const Network& rNetwork) {
for (int i = 0; i < rNetwork.n(); ++i) {
std::vector<int> neighAtDistOne;
@@ -46,6 +108,7 @@
neighAtDistOne.push_back(iter.actor());
}
}
+ // construct all pairs
vector<int>::const_iterator iterEnd = neighAtDistOne.end();
for (vector<int>::const_iterator outerIter = neighAtDistOne.begin();
outerIter != iterEnd; ++outerIter) {
@@ -58,9 +121,15 @@
}
}
+/**
+ * Initializes the layer given the reference network is a two mode
+ * network.
+ */
void DistanceTwoLayer::initializeTwoMode(const Network& rNetwork) {
// this is a two mode network so we do not need to check for loops
+ // nor do we have to store the reciever two paths.
for (int i = 0; i < rNetwork.m(); ++i) {
+ // construct all pairs
for (IncidentTieIterator outerIter = rNetwork.inTies(i);
outerIter.valid(); outerIter.next()) {
int outerActor = outerIter.actor();
@@ -75,11 +144,14 @@
}
}
-void DistanceTwoLayer::modifyTieValue(int ego, int alter, int val) {
- updateSingleTieValue(ego, alter, val);
- updateSingleTieValue(alter, ego, val);
-}
-
+/**
+ * Modifies the two-path count given the case the observed network is a
+ * one mode network.
+ * @param[in] rNetwork The observed network
+ * @param[in] ego The ego of the modified tie
+ * @param[in] alter The alter of the modified tie
+ * @param[in[ val The magnitude of modification
+ */
void DistanceTwoLayer::modify2PathCountOneMode(const Network& rNetwork, int ego,
int alter, int val) {
// if it is a loop or the edge (alter,ego) exists we have nothing to do
@@ -106,8 +178,18 @@
}
}
+/**
+ * Modifies the two-path count given the case the observed network is a
+ * two mode network.
+ * @param[in] rNetwork The observed network
+ * @param[in] ego The ego of the modified tie
+ * @param[in] alter The alter of the modified tie
+ * @param[in[ val The magnitude of modification
+ */
void DistanceTwoLayer::modify2PathCountTwoMode(const Network& rNetwork, int ego,
int alter, int val) {
+ // in a two mode network the exist no triangles, therefore it is
+ // sufficient to iterate over all incoming ties of alter
for (IncidentTieIterator iter = rNetwork.inTies(alter); iter.valid();
iter.next()) {
if (iter.actor() != ego) {
@@ -116,38 +198,29 @@
}
}
-void DistanceTwoLayer::onTieIntroductionEvent(const Network& rNetwork,
- const int ego, const int alter) {
- if (rNetwork.isOneMode()) {
- modify2PathCountOneMode(rNetwork, ego, alter, 1);
- } else {
- modify2PathCountTwoMode(rNetwork, ego, alter, -1);
- }
+/**
+ * Updates the tie value of <i>(ego,alter)</i> and <i>(alter,ego)</i>
+ * by <i>val</i>
+ * @param[in] ego The tie's ego
+ * @param[in] alter The tie's alter
+ * @param[in] val The magnitude of modification
+ */
+void DistanceTwoLayer::modifyTieValue(int ego, int alter, int val) {
+ updateSingleTieValue(ego, alter, val);
+ updateSingleTieValue(alter, ego, val);
}
-void DistanceTwoLayer::onTieWithdrawalEvent(const Network& rNetwork,
- const int ego, const int alter) {
- if (rNetwork.isOneMode()) {
- modify2PathCountOneMode(rNetwork, ego, alter, -1);
- } else {
- modify2PathCountTwoMode(rNetwork, ego, alter, -1);
- }
-}
-
-void DistanceTwoLayer::onNetworkClearEvent(const Network& rNetwork) {
- for (int i = 0; i < rNetwork.n(); ++i) {
- lpAdjacencies[i].clear();
- }
-}
-
-IncidentTieIterator DistanceTwoLayer::getDistanceTwoNeighbors(int ego) const {
- return IncidentTieIterator(lpAdjacencies[ego]);
-}
-
+/**
+ * Updates the value of tie <i>(ego,alter)</i> by <i>val</i>.
+ * @param[in] ego The ego of the modified tie
+ * @param[in] alter The alter of the modified tie
+ * @param[in[ val The magnitude of modification
+ */
void DistanceTwoLayer::updateSingleTieValue(int ego, int alter, int val) {
TieMap& egoMap = lpAdjacencies[ego];
TieMap::iterator iter = egoMap.lower_bound(alter);
- // we found the element
+ // if we found the element update the value and if needed remove
+ // the edge from the layer
if (iter != egoMap.end() && !egoMap.key_comp()(alter, iter->first)) {
int newVal = iter->second + val;
if (newVal) {
@@ -156,6 +229,7 @@
egoMap.erase(iter);
}
} else {
+ // insert the edge and use iter as hint (saves log)
egoMap.insert(iter, TieMap::value_type(alter, val));
}
}
Modified: pkg/RSienaTest/src/network/layers/DistanceTwoLayer.h
===================================================================
--- pkg/RSienaTest/src/network/layers/DistanceTwoLayer.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/layers/DistanceTwoLayer.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,13 @@
-/*
- * DistanceTwoLayer.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 05.08.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: DistanceTwoLayer.h
+ *
+ * Description: This module stores for each actor all its neighbors at
+ * distance two with respect to the observed network.
+ *****************************************************************************/
#ifndef DISTANCETWOLAYER_H_
#define DISTANCETWOLAYER_H_
@@ -15,34 +19,47 @@
namespace siena {
+// ----------------------------------------------------------------------------
+// Section: DistanceTwoLayer class
+// ----------------------------------------------------------------------------
+
class DistanceTwoLayer: public NetworkLayer {
public:
+
DistanceTwoLayer(const Network& rNetwork);
+
virtual ~DistanceTwoLayer();
- void initializeOneMode(const Network& rNetwork);
-
- void initializeTwoMode(const Network& rNetwork);
-
void onTieIntroductionEvent(const Network& rNetwork, const int ego,
const int alter);
+
void onTieWithdrawalEvent(const Network& rNetwork, const int ego,
const int alter);
void onNetworkClearEvent(const Network& rNetwork);
IncidentTieIterator getDistanceTwoNeighbors(int ego) const;
+
+protected:
+
+ void initialize(const Network& rNetwork);
+
private:
- void updateSingleTieValue(int ego, int alter, int val);
- void modifyTieValue(int ego, int alter, int val);
+ void initializeOneMode(const Network& rNetwork);
+ void initializeTwoMode(const Network& rNetwork);
+
void modify2PathCountOneMode(const Network& rNetwork, int ego, int alter,
int val);
void modify2PathCountTwoMode(const Network& rNetwork, int ego, int alter,
int val);
+ void modifyTieValue(int ego, int alter, int val);
+
+ void updateSingleTieValue(int ego, int alter, int val);
+
std::map<int, int>* lpAdjacencies;
};
Modified: pkg/RSienaTest/src/network/layers/NetworkLayer.h
===================================================================
--- pkg/RSienaTest/src/network/layers/NetworkLayer.h 2013-08-05 06:26:08 UTC (rev 237)
+++ pkg/RSienaTest/src/network/layers/NetworkLayer.h 2013-08-05 09:46:39 UTC (rev 238)
@@ -1,9 +1,14 @@
-/*
- * NetworkLayer.h
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
*
- * Created on: 05.08.2013
- * Author: ortmann
- */
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: NetworkLayer.h
+ *
+ * Description: This module defines the abstract NetworkLayer implementing
+ * the INetworkChangeListener class. It serves as the base class for any
+ * network layer.
+ *****************************************************************************/
#ifndef NETWORKLAYER_H_
#define NETWORKLAYER_H_
@@ -11,15 +16,34 @@
#include "../INetworkChangeListener.h"
namespace siena {
+
+// ----------------------------------------------------------------------------
+// Section: NetworkLayer abstract class
+// ----------------------------------------------------------------------------
+
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rsiena -r 238
More information about the Rsiena-commits
mailing list