Classes¶
Content
Distribution class¶
It represents a probability distribution on a set of elements.
-
class
Distribution
¶ Variables
-
int
num_el
¶ The number of elements in the set. It is also equal to
prob.size()
.
-
std::vector<long double>
prob
¶ It contains the probability of ocurrence of each element from a set.
Each value
prob[i]
is the probability of ocurrence of the ith element. The vector is indexed starting at position 0.Note
The vector prob is valid when all the elements are in the interval \([0,1]\) and the sum of all numbers in the vector is 1 with margin of error (upper or lower) equals to a constant epsilon by default set as 10e-6.
Constructors
-
Distribution
()¶ Default constructor.
-
Distribution
(std::string file)¶ Constructor used when the probability distribution is in a file.
- Parameters
file –
File name that contains a probability distribution. The file format must be the following:
n p1 p2 ... pn
where
n
is the number of elements in the set andpi
is the probability of the ith element ocurring.
-
Distribution
(std::vector<long double> &prob)¶ Constructor used when there is already a probability distribution in a vector.
- Parameters
prob – A vector containing a probability distribution.
-
Distribution
(int num_el, std::string type)¶ Constructor used to generate a uniform or a random probability distribution.
- Parameters
num_el – Number of elements in the set.
type – Must be
"uniform"
for generating a uniform distribution or"random"
for a random distribution.
Public functions
-
std::string
toString
(int precision)¶ Generates a string with the probability distribution.
- Parameters
precision – Decimal precision for long double numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
- Returns
A string containing the probabilities. The number of digits after de decimal point for each value will depend on
precision
. Each two values are separated by a space.
-
void
printToFile
(std::string file, int precision)¶ Prints the probability distribution in a file.
- Parameters
file – File name.
precision – Decimal precision for long double numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
The probability distribution will be printed in the following format:
n p1 p2 ... pn
where
n
is the number of elements in the probability distribution andpi
is the probability \(p(i)\) of the ith element occuring.
-
int
Channel class¶
A channel is a system that takes as input a secret \(x\), whose possible values come from a finite set \(\mathcal{X}\) , and whose only observable behavior is to produce an output \(y\), whose possible values come from a finite set \(\mathcal{Y}\).
-
class
Channel
¶ Variables
-
Distribution
prior
¶ A
Distribution
object used to represent the prior probability distribution on the set of secrets.
-
std::vector<std::vector<long double>>
matrix
¶ A channel matrix from \(\mathcal{X}\) to \(\mathcal{Y}\) whose rows give the distribution on the set of outputs. That is, entry
matrix[x][y]
denotes \(p(y|x)\), the conditional probability of getting output \(y\) given input \(x\). Note that all entries in a channel matrix are between 0 and 1, and each row sums to 1.Both rows and columns are indexed starting at position 0.
Note
To create a Channel object you need first to create a
Distribution
object, that keeps the prior distribution on the set of secrets.Constructors
-
Channel
()¶ Default constructor.
-
Channel
(Distribution &prior, std::string file)¶ Construtor used when the channel matrix is in a file.
- Parameters
prior – Prior distribution on the set of secrets.
file –
File name that contains a channel matrix. The file format must be the following:
n y p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets andy
is the number of outputs. Eachpij
denotes \(p(j|i)\) - the conditional probability of getting output \(j\) given input \(i\). Each two numbers must be separated by a space.
-
Channel
(Distribution &prior, std::vector<std::vector<long double>> &matrix)¶ Constructor used when there is already a channel matrix in a variable.
- Parameters
prior – Prior distribution on the set of secrets.
matrix – A channel matrix.
Warning
The number of rows in the channel matrix must be equal to
prior.num_el
.
-
Channel
(Distribution &prior, int num_out)¶ Constructor used to generate random channels. Given a set of secrets on
prior
, the constructor builds a random channel matrix.- Parameters
prior – Prior distribution on the set of secrets.
num_out – Number of outputs.
Public functions
-
static bool
isChannel
(std::vector<std::vector<long double>> &matrix)¶ Verifies if a matrix is a valid channel matrix. A channel matrix is valid if each row corresponds to a probability distribution.
- Parameters
matrix – A channel matrix.
- Returns
true
if the matrix is valid orfalse
otherwise.
-
std::string
toString
(int precision)¶ Generates a string with the channel matrix.
- Parameters
precision – Decimal precision for long double numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
- Returns
A string in the following format:
p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets andy
is the number of outputs. Eachpij
denotesp(j|i)
, the conditional probability of getting outputj
given inputi
. Each two numbers must be separated by a space.
-
void
printToFile
(std::string file, int precision)¶ Prints the channel matrix in a file.
- Parameters
file – File name to print the distribution.
precision – Decimal precision for long double numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
The channel matrix will be printed in the following format:
n y p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets andy
is the number of outputs. Eachpij
denotesp(j|i)
, the conditional probability of getting outputj
given inputi
. Each two numbers must be separated by a space.
-
Distribution
Hyper Class¶
Definition of hyper-distribution:
If \(\mathcal{X}\) is a finite set (of possible secret values), \(\pi\) is the prior distribution on \(\mathcal{X}\), and \(C\) is a channel, a hyper-distribution \([\pi \triangleright C]\) resulted from \(C\) on \(\pi\) is a distribution on distributions on \(\mathcal{X}\). Each output in an informational channel is a possible “world”, and each possible world is a new distribution on the set of secrets. We call the possible worlds the inner distributions. Each possible world has a probability of occurring, and we call the distribution on the possible worlds as the outer distribution.
-
class
Hyper
¶ Variables
-
Distribution
prior
¶ A probability distribution on a set of secrets.
-
int
num_post
¶ The number of posterior distributions yielded by
channel
andprior
.Note
The number of posterior distributions can be different from the number of outputs in channel. See
labels
for more details.
-
std::vector<std::vector<long double>>
joint
¶ Joint distribution matrix.
It is a matrix \(n\) x \(y\) where \(n\) is the number of secrets in the channel and \(y\) is the number of outputs in the channel. Each value
joint[i][j]
is the joint probability \(p(i,j)\). The joint distribution is build by multiplying the prior distribution by each row of the channel matrix.
-
Distribution
outer
¶ A distribution on posterior distributions.
Each value
outer.prob[i]
is the probability \(p(i)\) of the ith posterior distribution occuring, with \(0 \leq i <\)num_post-1
.
-
std::vector<std::vector<long double>>
inners
¶ Inner distributions matrix. It is a matrix \(n\) x \(y\) where \(n\) is the number of secrets (
prior.num_el
) and \(y\) is the number of posterior distributions (num_post
). Each valueinners[i][j]
corresponds to the conditional probability \(p(i|j)\), that is, the probability of the secret beingi
when the output isj
. Each column is a posterior distribution.Both rows and columns are indexed starting at position 0.
-
std::map<int, std::set<int>>
labels
¶ A map from posterior dsitributions indexes to a set of channel outputs indexes. When we look at the hyper-distrubtion, we have the outer distribution and the inner distributions. Depending on the prior distribution and the channel, the hyper-distribution may have two different outputs which yield the same posterior distribution on the set of secrets, and in this case, there is no difference for the adversary observing both.
Indeed we can simplify the representation of a hyper-distribution matrix mergin all equal columns in a single column, and sum their outer probabilities. We also delete a posterior column when its outer probability of ocurring is 0 (which means that this “world” has 0 probability of occuring).
The map key is the index of a posterior distribution in the reduced hyper-distribution matrix.
The map value of a key
i
is the set of channel outputs indexes which gave rise this single posterior distributioni
.
Example: If the outputs 2 and 4 from the channel yield the same posterior distribution, they are merged in, for example, the 3rd posterior distribution. Then,
labels[2]
(the 3rd posterior has index 2), you will have the set \(\{2,4\}\).
Constructors
-
Hyper
()¶ Default constructor.
-
Hyper
(std::string prior_file, std::string channel_file)¶ Constructor used when the prior distribution on the set of secrets and the channel are in a file.
- Parameters
prior_file –
File name that contains a probability distribution.
The file format must be the following:
n p1 p2 ... pn
where
n
is the number of elements in the distribution andpi
is the probability of the ith element occuring.channel_file –
File name that contains a channel matrix.
The file format must be the following:
n y p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets andy
is the number of outputs. Eachpij
value denotes \(p(j|i)\), the conditional probability of getting output \(j\) given input \(i\). Each two numbers must be separated by a space.
Warning
The number of rows in the channel matrix must be equal to the number of elements in the prior distribution.
-
Hyper
(Channel &channel)¶ Constructor used when there is already a Channel object in a variable.
Note
As a channel has the attribute
prior
(that corresponds to the prior distribution on the set of secrets), it is not necessary to give aDistribution
parameter in this constructor.- Parameters
channel – A
Channel
object.
Public functions
-
std::string
toString
(std::string type, int precision)¶ Generates a string with the
joint
matrix, theouter
distribution, theinners
or thelabels
.- Parameters
type – The name of what will be returned. It must be
"labels"
,"joint"
,"outer"
or"inners"
.precision – Decimal precision for float numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
The joint matrix will be returned in the following format:
p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets,y
is the number of channel outputs andpij
is the joint probability \(p(i,j)\).The outer distribution will be returned in the following format:
p1 p2 ... py
where
y
is the number of outputs.The inners matrix will be returned in the following format:
p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets,y
is the number of outputs andpij
is the conditional probability \(p(i|j)\).The labels will be returned in the following format:
1: x11 x12 ... 2: x21 x22 ... ... 3: xn1 xn2 ...
where
n
is the number of posteriors (num_post
) andxij
is an integer between 0 andchannel.num_out
.
Each two numbers in any choice are separated by a space.
-
void
printToFile
(std::string type, std::string file, int precision)¶ Prints the joint matrix, outer distribution, inners or the labels in a file.
- Parameters
type – The name of what will be returned. It must be
"labels"
,"joint"
,"outer"
or"inners"
.file – File name.
precision – Decimal precision for float numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
The joint matrix will be printed in the following format:
n y p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets,y
is the number of channel outputs andpij
is the joint probability \(p(i,j)\).The outer distribution will be printed in the following format:
y p1 p2 ... py
where
y
is the number of posterior distributions (num_post
) andpi
is the probability \(p(i)\) of the ith posterior distribution ocurring.The inners matrix will be printed in the following format:
n y p11 p12 ... p1y p21 p22 ... p2y ... pn1 pn2 ... pny
where
n
is the number of secrets,y
is the number of posterior distributions (num_post
) andpij
is the conditional probability \(p(i|j)\).The labels will be printed in the following format:
y 1: x11 x12 ... 2: x21 x22 ... ... y: xy1 xy2 ...
where
y
is the number of posterior distributions (num_post
) andxij
is an integer between 0 andchannel.num_out
.Each two numbers in any choice are are separated by a space.
-
void
rebuildHyper
(Distribution &prior)¶ Given a new prior distribution, rebuild the joint, outer and inner distributions.
- Parameters
prior – Prior distribution on a set of secrets.
Warning
The number of rows in the current channel matrix must be equal to the number of elements in the new prior distribution.
-
Distribution
Gain class¶
Definition of a gain function:
Given a finite, non-empty set \(\mathcal{X}\) (of possible secret values) and a non-empty set \(W\) (of possible actions), a gain function is a function \(g: W \times \mathcal{X} \rightarrow R\). The idea is that \(g(w, x)\) specifies the gain that the adversary achieves by taking action \(w\) when the actual value of the secret is \(x\).
-
class
Gain
¶ Variables
-
int
num_act
¶ Number of distinct actions that an adversary can take. This attribute is exactly the number of rows in
matrix
.
-
Distribution
prior
¶ A probability distribution on a set of secrets. It is a distribution on the set of secrets. See
Distribution
for more details.
-
std::vector<std::vector<long double>>
matrix
¶ Gain function matrix. It is a matrix \(w \times n\) where \(w\) is the number of actions that the adversary can take and \(n\) is the number of secrets. Each value
matrix[i][j]
is the gain that the adversary achieves by taking actioni
when the actual value of the secret isj
.Both rows and columns are indexed starting at position 0.
Constructors
-
Gain
()¶ Default constructor.
-
Gain
(Distribution &prior, std::string file)¶ Construtor used when the gain function matrix is in a file.
- Parameters
prior – Prior distribution on the set of secrets.
file –
File name which contains a gain function matrix. The file format must be the following:
w n g11 g12 ... g1n g21 g22 ... g2n ... gw1 gw2 ... gwn
where
w
is the number of actions (num_act
) andn
is the number of secrets. Each valuegij
is the gain of taking actioni
when the secret value isj
. Each two numbers must be separated by a space.
Warning
The number of columns in the gain function matrix must be the same as
prior.num_el
, i.e. the number of secrets in the distribution given in the first parameter.
-
Gain
(Distribution &prior, std::vector<std::vector<long double>> &matrix)¶ Constructor used when there is already a gain function matrix in a variable.
- Parameters
prior – Prior distribution on the set of secrets.
matrix – A gain function matrix.
Warning
The number of columns in the gain function matrix must be the same as
prior.num_el
, i.e. the number of secrets in the distribution given in the first parameter.
-
Gain
::
Gain
(Distribution &prior, int num_act, int MIN, int MAX)¶ Constructor used to generate a random gain function.
- Parameters
prior – Prior distribution on the set of secrets.
num_act – Number of actions.
MIN – Lower bound for the gain of an action.
MAX – Upper bound for the gain of an action.
The parameters
MIN
andMAX
must make up an interval. All the gains will be generated randomly in the interval[MIN,MAX]
.
Public functions
-
std::string
toString
(int precision)¶ Generates a string with the gain function matrix.
- Parameters
precision – Decimal precision for long double numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
- Returns
The gain function
matrix
will be returned in the following format:g11 g12 ... g1n g21 g22 ... g2n ... gw1 gw2 ... gwn
where each gain
gij
is the gain of taking actioni
when the secret value isj
. Each two numbers are separated by a space.
-
void
printToFile
(std::string file, int precision)¶ Prints the gain function matrix in a file.
- Parameters
file – File name.
precision – Decimal precision for long double numbers. For example, use the value 3 to print 0.322, use 5 to print 0.32197, and so on.
The gain function matrix will be printed in the following format:
w n g11 g12 ... g1n g21 g22 ... g2n ... gw1 gw2 ... gwn
where
w
is the number of actions (num_act
) andn
is the number of secrets. Each gaingij
is the gain of taking actioni
when the secret value isj
. Each two numbers are sparated by a space.
-
int


Wipe them out - all of them (when a design refresh doesn't work)
You created that shiney new version of your application, ran (in no particular order) fixup, compact and updall and replaced the design. Still some of the design elements haven't updated. Typically that happens when no attention was paid to the "prohibit design refresh" flag of the database design (all your predecessor's fault of course).
While you can go in and hunt the settings down one-by-one (tip: use an DXL export and just look for the property), it is sometimes faster and more profound to strip the offending database(s) from their design entirely before applying the "Replace Design" action.
To do that I use a script in my little universal toolbox. A word of caution:
While you can go in and hunt the settings down one-by-one (tip: use an DXL export and just look for the property), it is sometimes faster and more profound to strip the offending database(s) from their design entirely before applying the "Replace Design" action.
To do that I use a script in my little universal toolbox. A word of caution:
- Use it at your own risk
- Backup the database beforehand
- Check in Domino Designer's "Navigator view" (the Eclipse panel, not a Notes view) that they are all gone
- You have been warned
%REM
Class DesignWiper
Description: Wipes out entire design of a database
DEADLY for any folders that are user created
DEADLY on templates
Use at your own risk!
%END REM
Public Class DesignWiper
private db As NotesDatabase
%REM
Sub New
Description: The database is handed over in the constructor
%END REM
Sub New (dbToWipe As NotesDatabase )
Set me. db = dbToWipe
End Sub
%REM
Sub wipeDesign
Description: Wipes all design, might spare folders
%END REM
Public Sub wipeDesign (preserveFolders As Boolean )
Dim morituri As NotesNoteCollection
Dim curId As String
Dim nextId As String
If me. thisIsATemplate ( ) Then
MsgBox "I won't kill a template"
Exit sub
End If
'Select all elements and walk backwards
Set morituri = db. Createnotecollection ( true )
Call morituri. Selectalladminnotes ( false )
Call morituri. Selectalldatanotes ( false )
If preserveFolders Then
morituri. Selectfolders = false
End If
Call morituri. Buildcollection ( )
curId = morituri. Getfirstnoteid ( )
Do Until curId = ""
nextId = morituri. Getnextnoteid (curId )
Call me. wipeOne (curId )
curId = nextId
Loop
MsgBox "It is done, please run fixup, compact and design replace"
End Sub
%REM
Sub wipeOne
Description: Wipes one design element
might go wrong, so the error handler skips it
%END REM
Private Sub wipeOne (Noteid As String )
Dim doc As NotesDocument
On Error GoTo Err_wipeOne
Set doc = me. db. Getdocumentbyid (Noteid )
If Not doc Is Nothing Then
Call doc. Remove ( true )
End if
Exit_wipeOne:
Exit Sub
Err_wipeOne:
Print "Error removing " & NoteId & "(Error: " & CStr ( Err ) & " - " & Error$
Resume Exit_wipeOne
End Sub
%REM
Function thisIsATemplate
Description: checks if the database is a template
%END REM
Private Function thisIsATemplate As Boolean
thisIsATemplate = (db. Templatename <> "" )
End Function
End Class
Class DesignWiper
Description: Wipes out entire design of a database
DEADLY for any folders that are user created
DEADLY on templates
Use at your own risk!
%END REM
Public Class DesignWiper
private db As NotesDatabase
%REM
Sub New
Description: The database is handed over in the constructor
%END REM
Sub New (dbToWipe As NotesDatabase )
Set me. db = dbToWipe
End Sub
%REM
Sub wipeDesign
Description: Wipes all design, might spare folders
%END REM
Public Sub wipeDesign (preserveFolders As Boolean )
Dim morituri As NotesNoteCollection
Dim curId As String
Dim nextId As String
If me. thisIsATemplate ( ) Then
MsgBox "I won't kill a template"
Exit sub
End If
'Select all elements and walk backwards
Set morituri = db. Createnotecollection ( true )
Call morituri. Selectalladminnotes ( false )
Call morituri. Selectalldatanotes ( false )
If preserveFolders Then
morituri. Selectfolders = false
End If
Call morituri. Buildcollection ( )
curId = morituri. Getfirstnoteid ( )
Do Until curId = ""
nextId = morituri. Getnextnoteid (curId )
Call me. wipeOne (curId )
curId = nextId
Loop
MsgBox "It is done, please run fixup, compact and design replace"
End Sub
%REM
Sub wipeOne
Description: Wipes one design element
might go wrong, so the error handler skips it
%END REM
Private Sub wipeOne (Noteid As String )
Dim doc As NotesDocument
On Error GoTo Err_wipeOne
Set doc = me. db. Getdocumentbyid (Noteid )
If Not doc Is Nothing Then
Call doc. Remove ( true )
End if
Exit_wipeOne:
Exit Sub
Err_wipeOne:
Print "Error removing " & NoteId & "(Error: " & CStr ( Err ) & " - " & Error$
Resume Exit_wipeOne
End Sub
%REM
Function thisIsATemplate
Description: checks if the database is a template
%END REM
Private Function thisIsATemplate As Boolean
thisIsATemplate = (db. Templatename <> "" )
End Function
End Class
Posted by Stephan H Wissel on 05 April 2012 | Comments (b) | categories: Show-N-Tell Thursday


Welcome to BusMall Shopping Page
Dear Customer Please Vote For Your Favorite Products
To Vote Click On The Product Image
Thank You For Voting Dear Customer
To See The Vote Results Press The Button
Dear Customer Please Vote For Your Favorite Products
To Vote Click On The Product Image
Thank You For Voting Dear Customer
To See The Vote Results Press The Button


DISPOSABLE E-MAIL
MASTODON
PRIVATEBIN
SEARX
MIRROR
FREEDNS
MATRIX
FIREFOX SYNC
SPEEDTEST
OPERATIONTULIP
TOR BRIDGE
MORE COMING SOON


--- title: Bots keywords: fastai sidebar: home_sidebar summary: "Recipes for Bots" description: "Recipes for Bots" nb_path: "nbs/06_other/303_bots.ipynb" ---
Separate each set of commands into its own Cog
import discord
from discord.ext import commands
class Moderation(commands.Cog):
def __init__(self, bot, config):
self.bot = bot
self.config = config.cogs.Moderation
@commands.command()
async def kick(self, ctx, member: discord.Member, reason=None):
'''
Kick a member from this server.
Example: !kick user "toxic"
'''
await member.kick(reason=reason)
await ctx.send(f'{ctx.author} kicked {member}. Reason: {reason}')
@commands.command()
async def ban(self, ctx, member: discord.Member, reason=None):
'''
Ban a member from this server.
Example: !ban user "toxic"
'''
await member.ban(reason=reason)
await ctx.send(f'{ctx.author} banned {member}. Reason: {reason}')
Load a list of Cogs on startup
from operator import methodcaller
import discord
import lib.cogs
from discord.ext import commands
from lib.utilities import load_config, load_secrets
config = load_config('config.yml')
secrets = load_secrets('secrets.yml')
bot = commands.Bot(command_prefix=config.prefix)
for cog in config.cogs.keys():
cog_class = methodcaller(cog, bot=bot, config=config)(lib.cogs)
bot.add_cog(cog_class)
bot.run(secrets.token)


A base implementation of the Code First Data DataContext for Entity Framework
More...
List of all members.
Public Member Functions |
| | DataContext (string connectionString, IMappingConfiguration mapping, IContextConfiguration contextConfiguration=null, ILog log=null) |
| | Constructs a context
|
| IQueryable< T > | AsQueryable< T > () |
| | This gives a mockable wrapper around the normal DbSet{T} method that allows for testablity
|
| T | Add< T > (T item) |
| | Adds the provided instance of T to the data context
|
| T | Remove< T > (T item) |
| | Removes the provided instance of T from the data context
|
| T | Update< T > (T item) |
| | Updates the provided instance of T in the data context
|
| T | Attach< T > (T item) |
| | Attaches the provided instance of T to the data context
|
| T | Detach< T > (T item) |
| | Detaches the provided instance of T from the data context
|
| T | Reload< T > (T item) |
| | Reloads the provided instance of T from the database
|
| int | Commit () |
| | Commits all currently tracked entity changes
|
| IEnumerable< T > | ExecuteSqlQuery< T > (string sql, params DbParameter[] dbParams) |
| | Executes a SQL command and tries to map the returned datasets into an IEnumerable{T} The results should have the same column names as the Entity Type has properties
|
| int | ExecuteSqlCommand (string sql, params DbParameter[] dbParams) |
| | Executes a SQL command and returns the standard int return from the query
|
| int | ExecuteFunction (string procedureName, params ObjectParameter[] dbParams) |
| |
|
Protected Member Functions |
| override void | OnModelCreating (DbModelBuilder modelBuilder) |
| | This method is called when the model for a derived context has been initialized, but before the model has been locked down and used to initialize the context. The default implementation of this method takes the IMappingConfiguration array passed in on construction and applies them. If no configuration mappings were passed it it does nothing.
|
Properties |
| IEventManager | EventManager [get, set] |
| | The reference to EventManager that allows for ordered event handling and registration
|
Detailed Description
A base implementation of the Code First Data DataContext for Entity Framework
Constructor & Destructor Documentation
Constructs a context
- Parameters:
-
| connectionString | The standard SQL connection string for the Database |
| mapping | The Mapping Configuration that will determine how the tables and objects interact |
| contextConfiguration | The context specific configuration that will change context level behavior ( Optional ) |
| log | The logger being supplied for this context ( Optional ) |
Member Function Documentation
| T Highway.Data.DataContext.Add< T > |
( |
T |
item | ) |
|
|
inline |
Adds the provided instance of T to the data context
- Template Parameters:
-
| T | The Entity Type being added |
- Parameters:
-
| item | The T you want to add |
- Returns:
- The T you added
Implements Highway.Data.Interfaces.IDataContext.
| IQueryable<T> Highway.Data.DataContext.AsQueryable< T > |
( |
| ) |
|
|
inline |
This gives a mockable wrapper around the normal DbSet{T} method that allows for testablity
- Template Parameters:
-
| T | The Entity being queried |
- Returns:
- IQueryable{T}
Implements Highway.Data.Interfaces.IDataContext.
| T Highway.Data.DataContext.Attach< T > |
( |
T |
item | ) |
|
|
inline |
Attaches the provided instance of T to the data context
- Template Parameters:
-
| T | The Entity Type being attached |
- Parameters:
-
| item | The T you want to attach |
- Returns:
- The T you attached
Implements Highway.Data.Interfaces.IDataContext.
| int Highway.Data.DataContext.Commit |
( |
| ) |
|
|
inline |
| T Highway.Data.DataContext.Detach< T > |
( |
T |
item | ) |
|
|
inline |
Detaches the provided instance of T from the data context
- Template Parameters:
-
| T | The Entity Type being detached |
- Parameters:
-
| item | The T you want to detach |
- Returns:
- The T you detached
Implements Highway.Data.Interfaces.IDataContext.
| int Highway.Data.DataContext.ExecuteFunction |
( |
string |
procedureName, |
|
|
params ObjectParameter[] |
dbParams |
|
) |
| |
|
inline |
| int Highway.Data.DataContext.ExecuteSqlCommand |
( |
string |
sql, |
|
|
params DbParameter[] |
dbParams |
|
) |
| |
|
inline |
Executes a SQL command and returns the standard int return from the query
- Parameters:
-
| sql | The Sql Statement |
| dbParams | A List of Database Parameters for the Query |
- Returns:
- The rows affected
Implements Highway.Data.Interfaces.IDataContext.
| IEnumerable<T> Highway.Data.DataContext.ExecuteSqlQuery< T > |
( |
string |
sql, |
|
|
params DbParameter[] |
dbParams |
|
) |
| |
|
inline |
Executes a SQL command and tries to map the returned datasets into an IEnumerable{T} The results should have the same column names as the Entity Type has properties
- Template Parameters:
-
| T | The Entity Type that the return should be mapped to |
- Parameters:
-
| sql | The Sql Statement |
| dbParams | A List of Database Parameters for the Query |
- Returns:
- An IEnumerable{T} from the query return
Implements Highway.Data.Interfaces.IDataContext.
| override void Highway.Data.DataContext.OnModelCreating |
( |
DbModelBuilder |
modelBuilder | ) |
|
|
inlineprotected |
This method is called when the model for a derived context has been initialized, but before the model has been locked down and used to initialize the context. The default implementation of this method takes the IMappingConfiguration array passed in on construction and applies them. If no configuration mappings were passed it it does nothing.
Typically, this method is called only once when the first instance of a derived context is created. The model for that context is then cached and is for all further instances of the context in the app domain. This caching can be disabled by setting the ModelCaching property on the given ModelBuidler, but note that this can seriously degrade performance. More control over caching is provided through use of the DbModelBuilder and DbContextFactory classes directly.
- Parameters:
-
| modelBuilder | The builder that defines the model for the context being created. |
| T Highway.Data.DataContext.Reload< T > |
( |
T |
item | ) |
|
|
inline |
Reloads the provided instance of T from the database
- Template Parameters:
-
| T | The Entity Type being reloaded |
- Parameters:
-
| item | The T you want to reload |
- Returns:
- The T you reloaded
Implements Highway.Data.Interfaces.IDataContext.
| T Highway.Data.DataContext.Remove< T > |
( |
T |
item | ) |
|
|
inline |
Removes the provided instance of T from the data context
- Template Parameters:
-
| T | The Entity Type being removed |
- Parameters:
-
| item | The T you want to remove |
- Returns:
- The T you removed
Implements Highway.Data.Interfaces.IDataContext.
| T Highway.Data.DataContext.Update< T > |
( |
T |
item | ) |
|
|
inline |
Updates the provided instance of T in the data context
- Template Parameters:
-
| T | The Entity Type being updated |
- Parameters:
-
| item | The T you want to update |
- Returns:
- The T you updated
Implements Highway.Data.Interfaces.IDataContext.
Property Documentation
Event Documentation
The documentation for this class was generated from the following file:
- Highway.Data.EntityFramework/Contexts/DataContext.cs


|
Drake
|
Collision cliques filter collisions by defining a group (or clique) of collision elements. Membership in a clique precludes collision with any other member of that same clique. The underlying idea of collision cliques is that of the mathematical clique. This mathematical concept applies very naturally to the graph-based discussion of collision filtering. A clique in a graph is, loosely, a completely connected subgraph; there is an edge between each of the nodes in the subgraph. For collision filtering, that implies that all of the pairs that can be created from combinations of the clique members are filtered out.
It is common to simulate a robot such that collisions between any two bodies of the robot are ignored (see collision_filter_sdf_semantics). This behavior is easily represented with collision cliques; the whole robot belongs to a single clique.
In Drake, cliques are represented as integer identifiers. Each collision element tracks the set of cliques to which it belongs. When a pair of collision elements are considered for collision computation, their two sets of cliques are intersected; a non-empty resultant set means that this pair is filtered. The cost of the intersection is O(n + m)
, where the two elements belong to n
and m
different cliques, respectively. This is the worst case. In principle, it would come up whenever the pair of collision elements are not filtered by a clique. In practice, this cost is mitigated as follows:
O(n + m)
test in common cases.Drake automatically applies cliques in two different cases:
There are several implications of this:
A
and B
. Their collision elements will automatically be put into a common clique. However, we may want collisions between element E
on B
and collision elements on A
to not be filtered. We can create a massless body Z
to hold E
and use a weld (fixed) joint to attach Z
to B
. Z
will not be adjacent to A, so E
will interact with A
's elements.Next topic: Collision Filter Groups


Sethi Model
- author Carl Boettiger,
- license: CC0
Implements a numerical version of the SDP described in (Sethi et. al. 2005).
Clear the workspace and load package dependencies:
Define noise parameters
sigma_g <- 0.1 # Noise in population growth
sigma_m <- 0.1 # noise in stock assessment measurement
sigma_i <- 0.1 # noise in implementation of the quota
we’ll use log normal noise functions. For Reed, only z_g
will be random. Sethi et al will add the other forms of noise:
z_g <- function() rlnorm(1, 0, sigma_g) # mean 1
z_m <- function() rlnorm(1, 0, sigma_m) # mean 1
z_i <- function() rlnorm(1, 0, sigma_i) # mean 1
Chose the state equation / population dynamics function
f <- BevHolt
Note that the pdg-control
pacakge already has a definition for the BevHolt
function, (typing the function name prints the function)
BevHolt
function (x, h, p)
{
x <- max(0, x - h)
A <- p[1]
B <- p[2]
sapply(x, function(x) {
x <- max(0, x)
max(0, A * x/(1 + B * x))
})
}
<environment: namespace:pdgControl>
That is, \( f(x,h) = \)
Of course we could pass in any custom function of stocksize x
, harvest h
and parameter vector p
in place of BevHolt
. Note that we would need to write this function explicitly so that it can take vector values of x
(i.e. uses sapply
), an annoying feature of R
for users comming from Matlab.
We must now define parameters for the function. Note that the positive stationary root of the model is given by \( \), which we’ll store for future reference as K
.
pars <- c(1.5, 0.05)
K <- (pars[1] - 1)/pars[2]
and we use a harvest-based profit function with default parameters
profit <- profit_harvest(price=1, c0 = 0.01)
The profit_harvest
function has the form
\[ = h - ( c_0 + c_1 ) \]
conditioned on \( h > x \) and \(x > 0 \). Note that the R code defines a function from another function using a trick known as a closure. Again we could write a custom profit function as long as it can take a vector stock size x
and a scalar harvest level h
. Details for provided functions can be found in the manual, i.e. ?profit_harvest
.
Now we must set up the discrete grids for stock size and havest levels (which will use same resolution as for stock), in order to calculate the SDP solution. Here we set the gridsize to 100.
x_grid <- seq(0, 2 * K, length = 100)
h_grid <- x_grid
Calculate the transition matrix (with noise in growth only)
We calculate the stochastic transition matrix for the probability of going from any state \( x_t \) to any other state \( x_t+1 \) the following year, for each possible choice of harvest \( h_t \). This provides a look-up table for the dynamic programming calculations.
In the Sethi case, computing the distribution over multiple sources of noise is actually quite difficult. Simulation turns out to be more efficient than numerically integrating over each distribution. This code parallelizes the operation over four cores, but can be scaled to an arbitrary cluster.
require(snowfall)
sfInit(parallel=TRUE, cpu=4)
SDP_Mat <- SDP_by_simulation(f, pars, x_grid, h_grid, z_g, z_m, z_i, reps=999)
Library ggplot2 loaded.
Note that SDP_Mat
is specified from the calculation above, as are our grids and our profit function. OptTime
is the stopping time. xT
specifies a boundary condition at the stopping time. A reward for meeting this boundary must be specified for it to make any difference. delta
indicates the economic discount rate. Again, details are in the function documentation.
Find the optimum by dynamic programming
Bellman’s algorithm to compute the optimal solution for all possible trajectories.
opt <- find_dp_optim(SDP_Mat, x_grid, h_grid, OptTime=25, xT=0,
profit, delta=0.05, reward=0)
Simulate
Now we’ll simulate 100 replicates of this stochastic process under the optimal harvest policy determined above.
sims <- lapply(1:100, function(i){
ForwardSimulate(f, pars, x_grid, h_grid, x0=K, opt$D, z_g, z_m, z_i)
})
The forward simulation algorithm needs an initial condition x0
which we set equal to the carrying capacity, as well as our population dynamics f
, parameters pars
, grids, and noise coefficients. Recall in the Reed case only z_g
, growth, is stochastic, while in the Sethi example we now have three forms of stochasticity – growth, measurement, and implementation.
Summarize and plot the results
R makes it easy to work with this big replicate data set. We make data tidy (melt), fast (data.tables), and nicely labeled.
dat <- melt(sims, id=names(sims[[1]]))
dt <- data.table(dat)
setnames(dt, "L1", "reps") # names are nice
Plots
Let’s begin by looking at the dynamics of a single replicate. The line shows Reed’s S, the level above which the stock should be harvested (where catch should be the difference between stock and S). To confirm that this policy is being followed, note that harvesting only occurs when the stock is above this line, and harvest is proportional to the amount by which it is above. Change the replicate reps==
to see the results from a different replicate.
ggplot(subset(dt,reps==1)) +
geom_line(aes(time, fishstock)) +
geom_abline(intercept=opt$S, slope = 0) +
geom_line(aes(time, harvest), col="darkgreen")
This plot summarizes the stock dynamics by visualizing the replicates. Reed’s S shown again.
p1 <- ggplot(dt) + geom_abline(intercept=opt$S, slope = 0)
p1 + geom_line(aes(time, fishstock, group = reps), alpha = 0.2)
We can also look at the harvest dynamics:
p1 + geom_line(aes(time, harvest, group = reps), alpha = 0.1, col="darkgreen")
This strategy is supposed to be a constant-escapement strategy. We can visualize the escapement:
p1 + geom_line(aes(time, escapement, group = reps), alpha = 0.1, col="darkgrey")
Visualizing the optimal policy
Note that when the boundary is sufficiently far away, i.e. for the first couple timesteps, the optimal policy is stationary. The optimal policy is shown here over time, where the color indicates the harvest recommended for each possible stock value at that time (shown on the vertical axis). Observe that the solution does not correspond to a simple Reed-style rule.
policy <- melt(opt$D)
policy_zoom <- subset(policy, x_grid[Var1] < max(dt$fishstock) )
p5 <- ggplot(policy_zoom) +
geom_point(aes(Var2, (x_grid[Var1]), col=h_grid[value])) +
labs(x = "time", y = "fishstock") +
scale_colour_gradientn(colours = rainbow(4)) +
geom_abline(intercept=opt$S, slope = 0)
p5
The harvest intensity is limited by the stock size.
p6 <- ggplot(policy_zoom) +
geom_point(aes(Var2, (x_grid[Var1]), col=x_grid[Var1] - h_grid[value])) +
labs(x = "time", y = "fishstock") +
scale_colour_gradientn(colours = rainbow(4)) +
geom_abline(intercept=opt$S, slope = 0)
p6 + geom_line(aes(time, fishstock, group = reps), alpha = 0.1, data=dt)
References
Sethi G, Costello C, Fisher A, Hanemann M and Karp L (2005). “Fishery management under multiple uncertainty.” Journal of Environmental Economics and Management, 50. ISSN 00950696, https://dx.doi.org/10.1016/j.jeem.2004.11.005


9.3 Implementation and Analysis of
Binary Trees
Recall that
each node of a binary tree consists of three parts: a data
member and two pointers to its children. The structure
BiTreeNode represents an individual node of a
binary tree (see Example
9.1). As you would expect, this structure has three
members that correspond to those just mentioned. The structure
BiTree is the binary tree data structure (see
Example
9.1). This structure consists of four members:
size is the number of nodes in the tree,
compare is a member not used by binary trees
but by datatypes that will be derived later from binary trees,
destroy is the encapsulated destroy function
passed to bitree_init, and
root is a pointer to the top of the node
hierarchy.
Example 9.1.
Header for the Binary Tree Abstract Datatype /*****************************************************************************
* *
* ------------------------------- bitree.h ------------------------------- *
* *
*****************************************************************************/
#ifndef BITREE_H
#define BITREE_H
#include <stdlib.h>
/*****************************************************************************
* *
* Define a structure for binary tree nodes. *
* *
*****************************************************************************/
typedef struct BiTreeNode_ {
void *data;
struct BiTreeNode_ *left;
struct BiTreeNode_ *right;
} BiTreeNode;
/*****************************************************************************
* *
* Define a structure for binary trees. *
* *
*****************************************************************************/
typedef struct BiTree_ {
int size;
int (*compare)(const void *key1, const void *key2);
void (*destroy)(void *data);
BiTreeNode *root;
} BiTree;
/*****************************************************************************
* *
* --------------------------- Public Interface --------------------------- *
* *
*****************************************************************************/
void bitree_init(BiTree *tree, void (*destroy)(void *data));
void bitree_destroy(BiTree *tree);
int bitree_ins_left(BiTree *tree, BiTreeNode *node, const void *data);
int bitree_ins_right(BiTree *tree, BiTreeNode *node, const void *data);
void bitree_rem_left(BiTree *tree, BiTreeNode *node);
void bitree_rem_right(BiTree *tree, BiTreeNode *node);
int bitree_merge(BiTree *merge, BiTree *left, BiTree *right, const void *data);
#define bitree_size(tree) ((tree)->size)
#define bitree_root(tree) ((tree)->root)
#define bitree_is_eob(node) ((node) == NULL)
#define bitree_is_leaf(node) ((node)->left == NULL && (node)->right == NULL)
#define bitree_data(node) ((node)->data)
#define bitree_left(node) ((node)->left)
#define bitree_right(node) ((node)->right)
#endif
9.3.1 bitree_init
The bitree_init operation initializes a
binary tree so that it can be used in other operations (see Example
9.2). Initializing a binary tree is a simple operation in
which we set the size member of the tree to 0,
the destroy member to destroy,
and the root pointer to NULL.
The runtime complexity of bitree_init is O (1) because all of the steps in
initializing a binary tree run in a constant amount of
time.
9.3.2 bitree_destroy
The bitree_destroy operation destroys a
binary tree (see Example
9.2). Primarily this means removing all nodes from the
tree. The function passed as destroy to bitree_init is called once for each
node as it is removed, provided destroy was
not set to NULL.
The runtime complexity of bitree_destroy is O (n),
where n is the number of nodes
in the binary tree. This is because bitree_destroy simply calls bitree_rem_left, which runs in O (n)
time, where n is the number of
nodes in the tree.
9.3.3 bitree_ins_left
The bitree_ins_left operation inserts a
node into a binary tree as the left child of a specified node
(see Example
9.2). The call sets the new node to point to the data
passed by the caller. Linking the new node into the tree is
accomplished by setting the left pointer of
node to point to the new node. If
node is NULL and the tree is empty, we set the
root member of the tree data structure to the
new node. We update the size of the tree by incrementing the
size member.
The runtime complexity of bitree_ins_left is O (1) because all of the steps in
inserting a node into a binary tree run in a constant amount
of time.
9.3.4 bitree_ins_right
The bitree_ins_right operation inserts a
node into a binary tree as the right child of a specified node
(see Example
9.2). This operation works similarly to bitree_ins_left, except that linking
the new node into the tree is accomplished by setting the
right pointer of node to point
to the new node.
The runtime complexity of bitree_ins_right is O (1) because all of the steps in
inserting a node into a binary tree run in a constant amount
of time.
9.3.5 bitree_rem_left
The bitree_rem_left operation removes the
subtree rooted at the left child of a specified node (see Example
9.2). Nodes are removed by performing a postorder
traversal beginning at the left child of node.
If node is NULL, we begin the traversal at the
root node. The function passed as destroy to
bitree_init is called once for
each node as it is removed, provided destroy
was not set to NULL. As each node is removed, we update the
size member of the tree data structure as
well.
The runtime complexity of bitree_rem_left is O (n),
where n is the number of nodes
in the subtree rooted at the left child of
node. This is because bitree_rem_left performs a postorder
traversal to visit each of the nodes in the subtree while all
other parts of the operation run in a constant amount of
time.
9.3.6 bitree_rem_right
The bitree_rem_right operation removes
the subtree rooted at the right child of a specified node (see
Example
9.2). This operation works much like bitree_rem_left, except that nodes
are removed by performing a postorder traversal beginning at
the right child of node.
The runtime complexity of bitree_rem_right is O (n),
where n is the number of nodes
in the subtree rooted at the right child of
node. This is because bitree_rem_right performs a postorder
traversal to visit each of the nodes in the subtree while all
other parts of the operation run in a constant amount of
time.
9.3.7 bitree_merge
The bitree_merge operation merges two
binary trees into a single binary tree (see Example
9.2). First, we initialize merge by
calling bitree_init. Next, we
insert data into the merged tree at its root.
The merged tree's left and right children are then set to be
the root nodes of left and
right, and the size of the tree is adjusted to
reflect the sizes of the subtrees. Last, we detach the nodes
now in the merged tree from the original trees and set the
size of each tree to 0.
The runtime complexity of bitree_merge is O (1) because all of the steps in
merging two binary trees run in a constant amount of
time.
9.3.8 bitree_size, bitree_root,
bitree_is_eob, bitree_is_leaf, bitree_data, bitree_left,
bitree_right
These macros implement some of the simpler
binary tree operations (see Example
9.1). Generally, they provide an interface for accessing
and testing members of the BiTree and
BiTreeNode structures.
The runtime complexity of these operations
is O (1) because accessing and
testing members of a structure are simple tasks that run in a
constant amount of time.
Example 9.2.
Implementation of the Binary Tree Abstract Datatype /*****************************************************************************
* *
* ------------------------------- bitree.c ------------------------------- *
* *
*****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "bitree.h"
/*****************************************************************************
* *
* ------------------------------ bitree_init ----------------------------- *
* *
*****************************************************************************/
void bitree_init(BiTree *tree, void (*destroy)(void *data)) {
/*****************************************************************************
* *
* Initialize the binary tree. *
* *
*****************************************************************************/
tree->size = 0;
tree->destroy = destroy;
tree->root = NULL;
return;
}
/*****************************************************************************
* *
* ---------------------------- bitree_destroy ---------------------------- *
* *
*****************************************************************************/
void bitree_destroy(BiTree *tree) {
/*****************************************************************************
* *
* Remove all the nodes from the tree. *
* *
*****************************************************************************/
bitree_rem_left(tree, NULL);
/*****************************************************************************
* *
* No operations are allowed now, but clear the structure as a precaution. *
* *
*****************************************************************************/
memset(tree, 0, sizeof(BiTree));
return;
}
/*****************************************************************************
* *
* ---------------------------- bitree_ins_left --------------------------- *
* *
*****************************************************************************/
int bitree_ins_left(BiTree *tree, BiTreeNode *node, const void *data) {
BiTreeNode *new_node,
**position;
/*****************************************************************************
* *
* Determine where to insert the node. *
* *
*****************************************************************************/
if (node == NULL) {
/**************************************************************************
* *
* Allow insertion at the root only in an empty tree. *
* *
**************************************************************************/
if (bitree_size(tree) > 0)
return -1;
position = &tree->root;
}
else {
/**************************************************************************
* *
* Normally allow insertion only at the end of a branch. *
* *
**************************************************************************/
if (bitree_left(node) != NULL)
return -1;
position = &node->left;
}
/*****************************************************************************
* *
* Allocate storage for the node. *
* *
*****************************************************************************/
if ((new_node = (BiTreeNode *)malloc(sizeof(BiTreeNode))) == NULL)
return -1;
/*****************************************************************************
* *
* Insert the node into the tree. *
* *
*****************************************************************************/
new_node->data = (void *)data;
new_node->left = NULL;
new_node->right = NULL;
*position = new_node;
/*****************************************************************************
* *
* Adjust the size of the tree to account for the inserted node. *
* *
*****************************************************************************/
tree->size++;
return 0;
}
/*****************************************************************************
* *
* --------------------------- bitree_ins_right --------------------------- *
* *
*****************************************************************************/
int bitree_ins_right(BiTree *tree, BiTreeNode *node, const void *data) {
BiTreeNode *new_node,
**position;
/*****************************************************************************
* *
* Determine where to insert the node. *
* *
*****************************************************************************/
if (node == NULL) {
/**************************************************************************
* *
* Allow insertion at the root only in an empty tree. *
* *
**************************************************************************/
if (bitree_size(tree) > 0)
return -1;
position = &tree->root;
}
else {
/**************************************************************************
* *
* Normally allow insertion only at the end of a branch. *
* *
**************************************************************************/
if (bitree_right(node) != NULL)
return -1;
position = &node->right;
}
/*****************************************************************************
* *
* Allocate storage for the node. *
* *
*****************************************************************************/
if ((new_node = (BiTreeNode *)malloc(sizeof(BiTreeNode))) == NULL)
return -1;
/*****************************************************************************
* *
* Insert the node into the tree. *
* *
*****************************************************************************/
new_node->data = (void *)data;
new_node->left = NULL;
new_node->right = NULL;
*position = new_node;
/*****************************************************************************
* *
* Adjust the size of the tree to account for the inserted node. *
* *
*****************************************************************************/
tree->size++;
return 0;
}
/*****************************************************************************
* *
* ---------------------------- bitree_rem_left --------------------------- *
* *
*****************************************************************************/
void bitree_rem_left(BiTree *tree, BiTreeNode *node) {
BiTreeNode **position;
/*****************************************************************************
* *
* Do not allow removal from an empty tree. *
* *
*****************************************************************************/
if (bitree_size(tree) == 0)
return;
/*****************************************************************************
* *
* Determine where to remove nodes. *
* *
*****************************************************************************/
if (node == NULL)
position = &tree->root;
else
position = &node->left;
/*****************************************************************************
* *
* Remove the nodes. *
* *
*****************************************************************************/
if (*position != NULL) {
bitree_rem_left(tree, *position);
bitree_rem_right(tree, *position);
if (tree->destroy != NULL) {
/***********************************************************************
* *
* Call a user-defined function to free dynamically allocated data. *
* *
***********************************************************************/
tree->destroy((*position)->data);
}
free(*position);
*position = NULL;
/**************************************************************************
* *
* Adjust the size of the tree to account for the removed node. *
* *
**************************************************************************/
tree->size--;
}
return;
}
/*****************************************************************************
* *
* --------------------------- bitree_rem_right --------------------------- *
* *
*****************************************************************************/
void bitree_rem_right(BiTree *tree, BiTreeNode *node) {
BiTreeNode **position;
/*****************************************************************************
* *
* Do not allow removal from an empty tree. *
* *
*****************************************************************************/
if (bitree_size(tree) == 0)
return;
/*****************************************************************************
* *
* Determine where to remove nodes. *
* *
*****************************************************************************/
if (node == NULL)
position = &tree->root;
else
position = &node->right;
/*****************************************************************************
* *
* Remove the nodes. *
* *
*****************************************************************************/
if (*position != NULL) {
bitree_rem_left(tree, *position);
bitree_rem_right(tree, *position);
if (tree->destroy != NULL) {
/***********************************************************************
* *
* Call a user-defined function to free dynamically allocated data. *
* *
***********************************************************************/
tree->destroy((*position)->data);
}
free(*position);
*position = NULL;
/**************************************************************************
* *
* Adjust the size of the tree to account for the removed node. *
* *
**************************************************************************/
tree->size--;
}
return;
}
/*****************************************************************************
* *
* ----------------------------- bitree_merge ----------------------------- *
* *
*****************************************************************************/
int bitree_merge(BiTree *merge, BiTree *left, BiTree *right, const void
*data) {
/*****************************************************************************
* *
* Initialize the merged tree. *
* *
*****************************************************************************/
bitree_init(merge, left->destroy);
/*****************************************************************************
* *
* Insert the data for the root node of the merged tree. *
* *
*****************************************************************************/
if (bitree_ins_left(merge, NULL, data) != 0) {
bitree_destroy(merge);
return -1;
}
/*****************************************************************************
* *
* Merge the two binary trees into a single binary tree. *
* *
*****************************************************************************/
bitree_root(merge)->left = bitree_root(left);
bitree_root(merge)->right = bitree_root(right);
/*****************************************************************************
* *
* Adjust the size of the new binary tree. *
* *
*****************************************************************************/
merge->size = merge->size + bitree_size(left) + bitree_size(right);
/*****************************************************************************
* *
* Do not let the original trees access the merged nodes. *
* *
*****************************************************************************/
left->root = NULL;
left->size = 0;
right->root = NULL;
right->size = 0;
return 0;
}
|


Who are we?
We are a diverse cast of people, from various walks of life and from all over the world. What unites us is our love for web development.
Hey!
Currently we are concentrating on NGOs and other not-for-profit projects, so if you work for one, or know of one that could use a better website, get in touch with us.
We are a diverse cast of people, from various walks of life and from all over the world. What unites us is our love for web development.
Yup!
But why free?
Well, for one, it's our way of saying thank you for all the amazing work you're doing.
Two, we all got into web development as we love it. So this is just a way for us to continue doing what we love, while at the same time, giving back to the society.
Somewhere far away, there is a huge airconditioned place with floor to ceiling shelves/racks. And on each of these racks, there are lots of disks, each measured in terabytes.
Basically, we design websites. That's what we do.
We ensure that our UI is eye-catching and at the same time, easy to read.
Good looks need not compromise on performance.
We'll do the heavy-lifting and manage the code. So ]you can concentrate on doing what you do best.
For not-for-profit group/organization. You get an awesome website, we get a ton of experience.
Hey, thanks for your interest in us. We'll be sure to get back to you as soon as possible.


Invite auditor
First Name
Last Name
Email
Create Username
Create Password
Contact Number
audit
Teams
Bruce Wayne
Storage
60gb
/ 100gb
View Profile
Settings
Invite your friends
Sign Out
No auditor, invite them.
+ Invite Auditor


List all breeds
≡
↑
Find Dog You Love
List all Dog Breeds Images using
Dog.CEO API
by
Lam Pham
- The Man who loves Dogs.


Meditation Process
How did the 'process over product' concept affect the way you tackled the site redesign and rebuild?
I really struggled to resist the urge to change things from my wireframes mid way through coding it into the HTML and styling it, either to make it easier because I couldn't figure out how to make it do what I was wanting it to do, or because I thought it would make it look better.
I kept the 'process over product' mantra in my mind and resisted the urge to not follow my wireframes. I am glad in the end though because there is a little bit of satisfaction with being able to get from something I have drawn with a pen, to what is a functional webpage.
Search Inside Yourself, Chapter 2: Breathing as if you're life depends on it
Before reading this chapter, I was under the impression that meditation was just about training the attention. But after I read this chapter, I've realised that this isn't the whole purpose of doing meditation. It talks about how training the attention is like having a big flash light, as only when you use it to look for something in a dark room is it actually any use to you. This shows how the real purpose of meditating is to be able to 'search inside yourself' and view insights into your own mind that you can't usually detect.
I have already been doing a few of the heaspace.com meditation sessions, so I have had a few really satisfying sessions where my mind has constantly wandered off when I'm focusing on breathing, and I don't realise for a while and then I gently pull my focus back to breathing. In later sessions, my attention has wandered off less so I am getting a good indication that my mind is getting a mental 'workout' of sorts.


Please follow each step completely. Use the other lessons and resources (Mozilla Developer Network) to help you. You may also get help from your classmates. Kevin and Adam will be able to help, so if you get stuck, raise your hand to let them know.
Create a new folder in your top-level workspace directory called "scripts".
Inside that new folder, create a new file called memory.js
.
In your index.html file, we will add a


The Chenchus are a tribe residing mainly in Andhra Pradesh and speak a dialect of the Telugu language known as Chenchu. The Chenchus of Andhra Pradesh are quite forward in their thoughts, compared to the rest of Indian society, when it comes to matters of the heart. Chenchu youth are free to marry whoever they wish to. There is no form of parental pressure or aggression. Also, the clan is divided into Gotras (like our caste system), and generally they do not marry within the same Gotra. Unlike our rigid society, Chenchu tribes allow divorce, and widows too are allowed to remarry. Well, maybe our society can take a few 'lessons' from them?(Source)
The Chenchus are Adivasi, a designated Scheduled Tribe in the Indian states of Andhra Pradesh, Telangana, Karnataka and Odisha.[1] They are an aboriginal tribe whose traditional way of life been based on hunting and gathering. The Chenchus speak the Chenchu language, a member of the Dravidian language family. In general, the Chenchu relationship to non-tribal people has been largely symbiotic. Some Chenchus have continued to specialize in collecting forest products for sale to non-tribal people. Many Chenchus live in the dense Nallamala forest of Andhra Pradesh.
The Chenchus are referred to as one of the Primitive Tribal Groups that are still dependent on forests and do not cultivate land but hunt for a living. Non-tribe people living among them rent land from the Chenchus and pay a portion of the harvest. Dalits also settled among them with the help of the Chenchus and learned agriculture from them, and the nomadic Banjara herders who graze their cattle in the forest also have been allotted land there. The Chenchus have responded unenthusiastically to government efforts to induce them to take up agriculture themselves.(Source)
Chenchus are a Particularly Vulnerable Tribal Group whose hamlets or Pentas dot the Nallamala forest range spread across four to five districts in Telangana and Andhra Pradesh states. They are inveterate forest dwellers, who have, over centuries, steadfastly refused to move out of their woods regardless of the perils of such life. If patriotism be defined as love for the land, Chenchus are patriots in true spirit. The non-resident war cries on social media over imagined boundaries are no match for their raw affinity to forests where they live without basic facilities.
Love for life or prolonging of life, for one, is not the concern that bothers Chenchus ever. Baffling still, whenever the successive governments provided them agricultural lands in a bid to bring them out of forests, they died in higher numbers after losing the land to manipulative outsiders in return for hooch! They have no use for material wealth.
“They will live and die there. They will die even if they come out. So, we do not press them to go out,” says a forester, “For a Chenchu man who comes out on some work, entering the woods itself is coming home. His hamlet might be 30 kilometres farther, which he will walk slowly, resting occasionally, picking little forest treats, but he would have already let out a sigh, pleased with the idea of coming home.”
He also gives a peek into the uncanny shyness of Chenchus, whom a stranger may pester to no end with hundred questions, but extract no more than monosyllables.
“When this region was a Naxalite bastion, the revolutionaries would take shelter inside the hamlets. Chenchus would say no to neither — them or the police. Police would torture them endlessly, but silence is what they would be rewarded with.”
Well, it’s cacophony we need to sustain the “development” in our world, or to take the supposedly momentous, but dishonest decisions about reversing the damage done. But quiet and stillness is what the life in forests taught Chenchus, primarily a hunting, gathering tribe.
Mallikarjun, my host, was more articulate than the rest, owing to his association with city-based NGOs working for land and food rights. At 26, he was already married with two kids, and lived in a two-room house beside which he retained his bamboo-and-thatch hut typical of Chenchu Pentas. That night, after feeding me with jowar rotis and vegetable curry, he related to me the Chenchu way of life, and laid siege to my attention for hours. A tiny part of his narrative, I take the privilege to reproduce here.
Until Mallikarjun told, beehives, for me, were those dangling threats suspended from trees or rooftops, which we should steer clear of unless we wished to be stung to death.
There are many kinds, clarified Mallikarjun, and a method to take down each
(Source)


TDMultiStreamWriter Class Reference
| Inherits from | NSObject |
| Declared in | TDMultiStreamWriter.h |
Overview
A stream aggregator that reads from a concatenated sequence of other inputs.
Use this to combine multiple input streams (and data blobs) together into one.
This is useful when uploading multipart MIME bodies.
Tasks
-
– addStream:length:
-
– addStream:
-
– addData:
-
– addFileURL:
-
– addFile:
-
length
Total length of the stream.
propertyThis is just computed by adding the values passed to addStream:length:, and the lengths of the NSData objects and files added. If addStream: has been called (the version without length:) the length is unknown and will be returned as -1. (Many clients won't care about the length, but TDMultipartUploader does.)
-
– openForInputStream
Returns an input stream; reading from this will return the contents of all added streams in sequence.
This stream can be set as the HTTPBodyStream of an NSURLRequest. It is the caller's responsibility to close the returned stream.
-
– openForOutputTo:
Associates an output stream; the data from all of the added streams will be written to the output, asynchronously.
-
– close
-
isOpen
property -
error
property -
– allOutput
Convenience method that opens an output stream, collects all the data, and returns it.
-
– addInput:length:
-
– opened
Properties
length
Total length of the stream.
This is just computed by adding the values passed to addStream:length:, and the lengths of the NSData objects and files added.
If addStream: has been called (the version without length:) the length is unknown and will be returned as -1.
(Many clients won't care about the length, but TDMultipartUploader does.)
@property (readonly) SInt64 length
Discussion
Total length of the stream.
This is just computed by adding the values passed to addStream:length:, and the lengths of the NSData objects and files added.
If addStream: has been called (the version without length:) the length is unknown and will be returned as -1.
(Many clients won't care about the length, but TDMultipartUploader does.)
Declared In
TDMultiStreamWriter.h
Instance Methods
allOutput
Convenience method that opens an output stream, collects all the data, and returns it.
- (NSData *)allOutput
Discussion
Convenience method that opens an output stream, collects all the data, and returns it.
Declared In
TDMultiStreamWriter.h
openForInputStream
Returns an input stream; reading from this will return the contents of all added streams in sequence.
This stream can be set as the HTTPBodyStream of an NSURLRequest.
It is the caller's responsibility to close the returned stream.
- (NSInputStream *)openForInputStream
Discussion
Returns an input stream; reading from this will return the contents of all added streams in sequence.
This stream can be set as the HTTPBodyStream of an NSURLRequest.
It is the caller's responsibility to close the returned stream.
Declared In
TDMultiStreamWriter.h
openForOutputTo:
Associates an output stream; the data from all of the added streams will be written to the output, asynchronously.
- (void)openForOutputTo:(NSOutputStream *)output
Discussion
Associates an output stream; the data from all of the added streams will be written to the output, asynchronously.
Declared In
TDMultiStreamWriter.h


this page will contain all the latest News on polls all over india.
Congress wins the election this time around. more..
Congress wins the election this time around. more..
Congress wins the election this time around. more..
Congress wins the election this time around. more..
you can I-poll if you are registered to the website. For registration click here.
Already registered proceed to Login


List - an introduction
Here's a paragraph
Here comes another one paragraph
A subheading
now for a list or two:
- this is a bulleted list
- no order applied
- just a bunch of point we want to make
and here's another ordered list:
- this is the first item
- followed by this one
- and one more for luck