Skip to content

Commit

Permalink
[#37] Satisfy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
quicklizard99 committed Jun 7, 2018
1 parent f9090d4 commit 3e9ca3d
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src-x86_64
releases
build
.directory
.DS_Store
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: cheddar
Type: Package
Title: Analysis and Visualisation of Ecological Communities
Version: 0.1-632
Date: 2017-04-21
Date: 2018-06-06
Author: Lawrence Hudson with contributions from Dan Reuman and Rob Emerson
Maintainer: Lawrence Hudson <quicklizard@googlemail.com>
Description: Provides a flexible, extendable representation of an ecological community and a range of functions for analysis and visualisation, focusing on food web, body mass and numerical abundance data. Allows inter-web comparisons such as examining changes in community structure over environmental, temporal or spatial gradients.
Expand Down
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ S3method(print, CommunityCollection)
S3method(subset, CommunityCollection)
S3method(summary, Community)
S3method(summary, CommunityCollection)
S3method('$<-', Community)
S3method('$<-', CommunityCollection)
S3method('[', CommunityCollection)
S3method('[<-', Community)
S3method('[<-', CommunityCollection)
S3method('[[<-', Community)
S3method('[[<-', CommunityCollection)
4 changes: 2 additions & 2 deletions man/cheddar.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ release history:
\tabular{ll}{
Package: \tab cheddar\cr
Type: \tab Package\cr
Version: \tab 0.1-631\cr
Date: \tab 2017-04-21\cr
Version: \tab 0.1-632\cr
Date: \tab 2018-06-06\cr
License: \tab BSD 2 clause\cr
}
}
Expand Down
1 change: 1 addition & 0 deletions src/anneal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <functional>
#include <vector>

#include "cheddar.h"
#include "cheddar_exception.h"

//#define DEBUG_ANNEAL
Expand Down
72 changes: 72 additions & 0 deletions src/cheddar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <R.h>
#include <Rinternals.h>
#include <R_ext/Rdynload.h>

#include "cheddar.h"


extern "C"
{

static const R_CMethodDef cMethods[] = {
{
"trophic_chains_size", (DL_FUNC) &trophic_chains_size, 8,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP
}
},
{
"print_chains", (DL_FUNC) &print_chains, 6,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP
}
},
{
"trophic_chains", (DL_FUNC) &trophic_chains, 9,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP
}
},
{
"trophic_chains_stats", (DL_FUNC) &trophic_chains_stats, 10,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP,
INTSXP
}
},
{
"shortest_paths", (DL_FUNC) &shortest_paths, 8,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, INTSXP, INTSXP, REALSXP, INTSXP, REALSXP, INTSXP
}
},
{
"sum_diet_gaps", (DL_FUNC) &sum_diet_gaps, 5,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, INTSXP, INTSXP, INTSXP
}
},
{
"minimise_sum_diet_gaps", (DL_FUNC) &minimise_sum_diet_gaps, 10,
(R_NativePrimitiveArgType [])
{
INTSXP, INTSXP, REALSXP, REALSXP, REALSXP, INTSXP, INTSXP, INTSXP, INTSXP,
INTSXP
}
},
{NULL, NULL, 0, NULL},
};

void R_init_myLib(DllInfo *info)
{
R_registerRoutines(info, cMethods, NULL, NULL, NULL);
R_useDynamicSymbols(info, FALSE);
}

} // extern C
65 changes: 65 additions & 0 deletions src/cheddar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
extern "C"
{

void sum_diet_gaps(const int *network, const int *nodes,
const int *row_order,
int *sum_diet_gaps,
int *status);

void minimise_sum_diet_gaps(const int *network,
const int *nodes,
const double *T_start,
const double *T_stop,
const double *c,
const int *swaps_per_T,
const int *trace_anneal,
int *best_cost,
int *best,
int *status);

void trophic_chains_size(const int *adjacency,
const int *adjacency_length,
const int *is_basal,
const int *node_count,
const int *test_overflow,
const int *max_queue,
int *n_chains,
int *longest,
int *status);

void print_chains(const int *adjacency,
const int *adjacency_length,
const int *is_basal,
const int *node_count,
const int *max_queue,
int *status);

void trophic_chains(const int *adjacency,
const int *adjacency_length,
const int *is_basal,
const int *node_count,
const int *ncols,
const int *nrows,
const int *max_queue,
int *chains,
int *status);

void trophic_chains_stats(const int *adjacency,
const int *adjacency_length,
const int *is_basal,
const int *node_count,
const int *n_chains,
const int *longest,
const int *max_queue,
int *node_pos_counts,
int *chain_lengths,
int *status);

void shortest_paths(const int *consumers, const int *consumers_length,
const int *resources, const int *resources_length,
const double *weights,
const int *node_count,
double *lengths,
int *status);

}
12 changes: 11 additions & 1 deletion src/shortest_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
#include <R.h>
#include <Rmath.h>
#include <vector>

#include "cheddar.h"

typedef std::vector<bool> BoolVector;
typedef std::vector<int> IntVector;
typedef std::vector<double> DoubleVector;

/*#define DEBUG_DIJKSTRA*/
#ifdef DEBUG_DIJKSTRA
#define DEBUG(X) { X; }
#else
#define DEBUG(X)
#endif
#ifdef DEBUG_DIJKSTRA


static void print_weights(const DoubleVector &weights, int n)
{
for(int row=0; row<n; ++row)
Expand All @@ -25,6 +31,7 @@ static void print_weights(const DoubleVector &weights, int n)
Rprintf("\n");
}
}

static void print_adjacency(const IntVector &adjacency, int n)
{
for(int i=0; i<n; ++i)
Expand All @@ -36,6 +43,7 @@ static void print_adjacency(const IntVector &adjacency, int n)
}
}
#endif

static DoubleVector dijkstra(const IntVector &consumers,
const IntVector &resources,
const DoubleVector &weights,
Expand Down Expand Up @@ -104,6 +112,7 @@ static DoubleVector dijkstra(const IntVector &consumers,
}
return (lengths);
}

extern "C"
{
void shortest_paths(const int *consumers, const int *consumers_length,
Expand Down Expand Up @@ -160,4 +169,5 @@ resources_length: the number of ints in resources
REprintf("Unexpected error in shortest_paths\n");
}
}
} // extern C

} // extern C

0 comments on commit 3e9ca3d

Please sign in to comment.