Skip to content

Instantly share code, notes, and snippets.

@kris7t
Last active April 1, 2016 21:40
Show Gist options
  • Save kris7t/6343f14058c6dfa99e5de32d93b28a8e to your computer and use it in GitHub Desktop.
Save kris7t/6343f14058c6dfa99e5de32d93b28a8e to your computer and use it in GitHub Desktop.
using NUnit.Framework;
using Pdn.LinearAlgebra;
using Pdn.LinearAlgebra.Concrete;
using Pdn.Workflows.TestFramework;
namespace Pdn.Stochastic.Tests.Steadystate
{
[TestFixture, WithWorkflow]
public class BicgstabTest : WorkflowTestFixture
{
private const double tolerance = 1e-10;
[Test]
public void SparseSharedResource()
{
var operationContext = new OperationContext(PredefinedOperationConfiguration.Parallel);
using (var mathContext = new MathContextWithOperationContext(operationContext))
{
var matrix = mathContext.CreateDisposableSparseMatrix(new double[,]
{
{-2, 1, 1, 0, 0, 0, 0, 0},
{0, -2, 0, 1, 1, 0, 0, 0},
{0, 0, -2, 1, 0, 0, 1, 0},
{0, 0, 0, -2, 0, 1, 0, 1},
{1, 0, 0, 0, -2, 1, 0, 0},
{0, 0, 1, 0, 0, -1, 0, 0},
{1, 0, 0, 0, 0, 0, -2, 1},
{0, 1, 0, 0, 0, 0, 0, -1}
});
var output = Workflow(mathContext: mathContext, matrix: matrix, tolerance: tolerance);
var expectedVector = mathContext.CreateArrayVector(
0.0666666666666666, 0.133333333333333, 0.133333333333333, 0.133333333333333,
0.0666666666666666, 0.200000000000000, 0.0666666666666666, 0.200000000000000);
expectedVector.Add(output.Result, -1);
Assert.That(expectedVector.L1Norm(), Is.LessThanOrEqualTo(tolerance));
}
}
}
}
<Workflow xmlns="http://petridotnet.inf.mit.bme.hu/pdn/2016/xaml/analysis"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<Workflow.Inputs>
<Input Name="MathContext" Type="IMathContext" Scope="Dependency"/>
<Input Name="Matrix" Type="{IMatrix system:Double}" DomainType="GeneratorMatrixAttribute"/>
<Input Name="Tolerance" Type="system:Double"/>
</Workflow.Inputs>
<Workflow.Outputs>
<Output Name="Result" Value="{Wire SteadyStateResult, SourceName=Solver}"/>
</Workflow.Outputs>
<UniformProbabilityVectorAlgorithm />
<MarkovianSteadyStateAlgorithm x:Name="Solver">
<NormalizingLinearEquationSolverAlgorithm>
<BicgstabAlgorithm Tolerance="{Wire Tolerance, Source={ThisWorkflow}}"/>
</NormalizingLinearEquationSolverAlgorithm>
</MarkovianSteadyStateAlgorithm>
</Workflow>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment