本文整理汇总了C#中IRange类的典型用法代码示例。如果您正苦于以下问题:C# IRange类的具体用法?C# IRange怎么用?C# IRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRange类属于命名空间,在下文中一共展示了IRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersects
internal static bool Intersects(IRange range1, IRange range2)
{
Contract.Requires(range1 != null);
Contract.Requires(range2 != null);
return range2.End > range1.Start && range1.End > range2.Start;
}
示例2: Main
public static void Main(string[] args)
{
try {
Cplex cplex = new Cplex();
IRange[] row = new IRange[3];
INumVar[] var = populateByRow(cplex, row);
if ( cplex.Solve() ) {
double[] x = cplex.GetValues(var);
double[] slack = cplex.GetSlacks(row);
System.Console.WriteLine("Solution status = " + cplex.GetStatus());
System.Console.WriteLine("Solution value = " + cplex.ObjValue);
int ncols = x.Length;
for (int j = 0; j < ncols; ++j)
System.Console.WriteLine("Variable " + j +
": Value = " + x[j]);
int nrows = slack.Length;
for (int i = 0; i < nrows; ++i)
System.Console.WriteLine("Constraint " + i +
": Slack = " + slack[i]);
cplex.ExportModel("qcpex1.lp");
}
cplex.End();
}
catch (ILOG.Concert.Exception e) {
System.Console.WriteLine("Concert exception '" + e + "' caught");
}
}
示例3: populateByRow
internal static INumVar[] populateByRow(IMPModeler model,
IRange[] row)
{
double[] lb = {0.0, 0.0, 0.0};
double[] ub = {40.0, System.Double.MaxValue, System.Double.MaxValue};
INumVar[] x = model.NumVarArray(3, lb, ub);
// - x0 + x1 + x2 <= 20
// x0 - 3*x1 + x2 <= 30
double[][] val = {new double[]{-1.0, 1.0, 1.0},
new double[]{ 1.0, -3.0, 1.0}};
row[0] = model.AddLe(model.ScalProd(val[0], x), 20.0);
row[1] = model.AddLe(model.ScalProd(val[1], x), 30.0);
// x0*x0 + x1*x1 + x2*x2 <= 1.0
row[2] = model.AddLe(model.Sum(model.Prod(x[0], x[0]),
model.Prod(x[1], x[1]),
model.Prod(x[2], x[2])), 1.0);
// Q = 0.5 ( 33*x0*x0 + 22*x1*x1 + 11*x2*x2 - 12*x0*x1 - 23*x1*x2 )
INumExpr x00 = model.Prod( 33.0, x[0], x[0]);
INumExpr x11 = model.Prod( 22.0, x[1], x[1]);
INumExpr x22 = model.Prod( 11.0, x[2], x[2]);
INumExpr x01 = model.Prod(-12.0, x[0], x[1]);
INumExpr x12 = model.Prod(-23.0, x[1], x[2]);
INumExpr Q = model.Prod(0.5, model.Sum(x00, x11, x22, x01, x12));
// maximize x0 + 2*x1 + 3*x2 + Q
double[] objvals = {1.0, 2.0, 3.0};
model.Add(model.Maximize(model.Diff(model.ScalProd(x, objvals), Q)));
return x;
}
示例4: Column
public Column(IRange constraint, double constrCoef)
{
this.objCoef = 0;
this.objCoefSet = false;
this.column = new GRBColumn();
this.column.AddTerm(constrCoef, constraint.GetConstr());
}
示例5: MonthsOverAvailableCapacity
public IEnumerable<Month> MonthsOverAvailableCapacity(IRange<Month> months)
{
return months.Collect( month =>
{
return IsOverCapacity(month);
});
}
示例6: Includes
internal static bool Includes(IRange range, IRange maybeIncludedRange)
{
Contract.Requires(range != null);
Contract.Requires(maybeIncludedRange != null);
return range.Start <= maybeIncludedRange.Start && maybeIncludedRange.End <= range.End;
}
示例7: Main
public static void Main(string[] args) {
if ( args.Length != 1 || args[0].ToCharArray()[0] != '-' ) {
Usage();
return;
}
try {
// Create the modeler/solver object
Cplex cplex = new Cplex();
INumVar[][] var = new INumVar[1][];
IRange[][] rng = new IRange[1][];
// Evaluate command line option and call appropriate populate method.
// The created ranges and variables are returned as element 0 of arrays
// var and rng.
switch ( args[0].ToCharArray()[1] ) {
case 'r': PopulateByRow(cplex, var, rng);
break;
case 'c': PopulateByColumn(cplex, var, rng);
break;
case 'n': PopulateByNonzero(cplex, var, rng);
break;
default: Usage();
return;
}
// write model to file
cplex.ExportModel("lpex1.lp");
// solve the model and display the solution if one was found
if ( cplex.Solve() ) {
double[] x = cplex.GetValues(var[0]);
double[] dj = cplex.GetReducedCosts(var[0]);
double[] pi = cplex.GetDuals(rng[0]);
double[] slack = cplex.GetSlacks(rng[0]);
cplex.Output().WriteLine("Solution status = " + cplex.GetStatus());
cplex.Output().WriteLine("Solution value = " + cplex.ObjValue);
int nvars = x.Length;
for (int j = 0; j < nvars; ++j) {
cplex.Output().WriteLine("Variable " + j +
": Value = " + x[j] +
" Reduced cost = " + dj[j]);
}
int ncons = slack.Length;
for (int i = 0; i < ncons; ++i) {
cplex.Output().WriteLine("Constraint " + i +
": Slack = " + slack[i] +
" Pi = " + pi[i]);
}
}
cplex.End();
}
catch (ILOG.Concert.Exception e) {
System.Console.WriteLine("Concert exception '" + e + "' caught");
}
}
示例8: Main
public static void Main(string[] args) {
try {
Cplex cplex = new Cplex();
INumVar[][] var = new INumVar[1][];
IRange[][] rng = new IRange[1][];
PopulateByRow(cplex, var, rng);
if ( cplex.Solve() ) {
double[] x = cplex.GetValues(var[0]);
double[] slack = cplex.GetSlacks(rng[0]);
System.Console.WriteLine("Solution status = " + cplex.GetStatus());
System.Console.WriteLine("Solution value = " + cplex.ObjValue);
for (int j = 0; j < x.Length; ++j) {
System.Console.WriteLine("Variable " + j +
": Value = " + x[j]);
}
for (int i = 0; i < slack.Length; ++i) {
System.Console.WriteLine("Constraint " + i +
": Slack = " + slack[i]);
}
}
cplex.ExportModel("mipex1.lp");
cplex.End();
}
catch (ILOG.Concert.Exception e) {
System.Console.WriteLine("Concert exception caught '" + e + "' caught");
}
}
示例9: OriginalToModifiedRange
public IRange OriginalToModifiedRange(IRange originalRange)
{
Contract.Requires(originalRange != null);
Contract.Requires(originalRange.Start >= 0);
Contract.Requires(originalRange.Start <= originalRange.End);
Contract.Requires(originalRange.End <= OriginalContent.Length);
int start = originalRange.Start;
int end = originalRange.End;
foreach(Change change in changes){
int oldStart = start;
if(change.Range.End <= start){
start += change.LengthDifference;
}
if(change.Range.End <= end){
end += change.LengthDifference;
System.Diagnostics.Trace.WriteLineIf(change.Range.End > oldStart,
"Warning: text was changed overlapping with the range which had been looked up: " + originalRange + " change: " + change);
}
else if(change.Range.Start < end)
{
end = Math.Min(end, change.Range.End);
System.Diagnostics.Trace.WriteLine(
"Warning: text was changed inside the range which had been looked up: " + originalRange + " change: " + change);
}
}
return new Range(start, start + originalRange.Length);
}
示例10: PopulateByRow
internal static void PopulateByRow (IMPModeler model,
INumVar[][] var,
IRange[][] rng) {
// First define the variables, three continuous and one integer
double[] xlb = {0.0, 0.0, 0.0, 2.0};
double[] xub = {40.0, System.Double.MaxValue,
System.Double.MaxValue, 3.0};
NumVarType[] xt = {NumVarType.Float, NumVarType.Float,
NumVarType.Float, NumVarType.Int};
INumVar[] x = model.NumVarArray(4, xlb, xub, xt);
var[0] = x;
// Objective Function: maximize x0 + 2*x1 + 3*x2 + x3
double[] objvals = {1.0, 2.0, 3.0, 1.0};
model.AddMaximize(model.ScalProd(x, objvals));
// Three constraints
rng[0] = new IRange[3];
// - x0 + x1 + x2 + 10*x3 <= 20
rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
model.Prod( 1.0, x[1]),
model.Prod( 1.0, x[2]),
model.Prod(10.0, x[3])), 20.0);
// x0 - 3*x1 + x2 <= 30
rng[0][1] = model.AddLe(model.Sum(model.Prod( 1.0, x[0]),
model.Prod(-3.0, x[1]),
model.Prod( 1.0, x[2])), 30.0);
// x1 - 3.5*x3 = 0
rng[0][2] = model.AddEq(model.Sum(model.Prod( 1.0, x[1]),
model.Prod(-3.5, x[3])), 0.0);
}
示例11: ExtractExcelCellProperty
public override Cell ExtractExcelCellProperty(IRange excelCell)
{
Cell cell = ExcelReader.ExtractExcelCellProperty(excelCell);
cell.Borders = GetBorders(excelCell);
return cell;
}
示例12: Main
// Step 7
public static void Main(string[] args)
{
if ( args.Length != 1 || args[0].ToCharArray()[0] != '-' ) {
Usage();
return;
}
try {
//Step 3
INumVar[][] var = new INumVar[1][];
IRange[][] rng = new IRange[1][];
// Step 8
// Step 11
// Step 9
// Step 10
cplex.End();
}
catch (ILOG.Concert.Exception e) {
System.Console.WriteLine("Concert exception '" + e + "' caught");
}
}
示例13: Match
public Match(string content, IRange range)
{
Contract.Requires(content != null);
Contract.Requires(range != null);
Content = content;
Range = range;
}
示例14: Setup
public override void Setup(IRange range)
{
base.Setup(range);
builder.Setup(range);
foreach (var decorator in decorators)
decorator.Setup(range);
}
示例15: SetUp
public void SetUp()
{
var rangesInWorksheet = new IRange[3][];
for (int i = 0; i < rangesInWorksheet.Length; i++)
{
rangesInWorksheet[i] = A.CollectionOfFake<IRange>(4).ToArray();
for (int j = 0; j < rangesInWorksheet[i].Length; j++)
{
A.CallTo(() => rangesInWorksheet[i][j].Text).Returns(string.Format("{0} {1}", i+1, j+1));
}
}
var range = A.Fake<IRange>();
for (int i = 0; i < rangesInWorksheet.Length; i++)
{
for (int j = 0; j < rangesInWorksheet[i].Length; j++)
{
A.CallTo(() => range[i+1, j+1]).Returns(rangesInWorksheet[i][j]);
}
}
_worksheet = A.Fake<IWorksheet>();
A.CallTo(() => _worksheet.Name).Returns("WorksheetName");
A.CallTo(() => _worksheet.Cells).Returns(range);
_sut = ExcelReaderFactory.CreateExcelReader();
}