| mmexset-cs/mmexset.cs | 
| /********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexset.cs                                     */
/*  ```````````````                                     */
/*  Example for the use of the Mosel libraries          */
/*  (accessing sets in Mosel)                           */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: J. Farmer & S. Heipcke                  */
/********************************************************/
using System;
using System.IO;
using Mosel;
namespace mmexset {
  public class mmexsetClass {
    /// <summary>
    /// Main entry point for the application
    /// </summary>
    [STAThread]
    static void Main(string[] args) {
      XPRM mosel;
      XPRMModel mod;
      XPRMSet set;
      int first, last;
      // Initialise Mosel
      mosel = XPRM.Init();
      // Set Mosel work directory to folder containing our example source code
      mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;
      /// Load a BIM file
      mod = mosel.CompileAndLoad("Models/burglari.mos");
      // Ru the model
      mod.Run();
      // Get the model object named 'ITEMS'
      // (it must be a set)
      set = (XPRMSet) mod.FindIdentifier("ITEMS");
      if (!set.IsEmpty) {
        // Items in a set are indexed by numbers
        // So get the number of the first and last indexes
        first = set.FirstIndex;
        last = set.LastIndex;
        Console.WriteLine("Elements of set ITEMS:");
        for (int i=first;i<=last;i++)
          Console.Write(" {0}, ", set.GetAsString(i));
        Console.WriteLine();
      }
      // We've written this explicitely to demonstrate set access, but the set
      // actually knows how to output itself.  Uncomment the following line to
      // see how it does this.
      // Console.WriteLine(set);
      if (set.GetIndex("CD player")<0)
        Console.WriteLine("'CD player' is not contained in 'ITEMS',");
    }
  }
}
 | 
| 
 | 
| mmexset-cs/mmexset.csproj | 
| <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="../Models/**" CopyToOutputDirectory="Always" LinkBase="Models" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="FICO.Xpress.XPRMdn" Version="5.6.1" /> 
  </ItemGroup>
  
</Project> | 
| 
 | 
| mmexas-cs/mmexas.cs | 
| /********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexas.cs                                      */
/*  ``````````````                                      */
/*  Example for the use of the Mosel libraries          */
/*  (using arrays with index sets: different ways       */
/*   of enumerating arrays)                             */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: J.Farmer & S. Heipcke                   */
/********************************************************/
using System;
using System.IO;
using Mosel;
namespace mmexas {
  public class mmexasClass {
    /// <summary>
    /// Main entry point for the application
    /// </summary>
    [STAThread]
    static void Main(string[] args) {
      XPRM mosel;
      XPRMModel mod;
      XPRMArray varr;
      XPRMSet[] sets;
      XPRMValue[] vindex;
      int dim;
      // Initialise Mosel
      mosel = XPRM.Init();
      // Set Mosel work directory to folder containing our example source code
      mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;
      // Compile and load a model from a file
      mod = mosel.CompileAndLoad("Models/trans.mos");
      // Run the model;
      mod.Run();
      // Get the model object named 'x'
      // It must be an array
      varr = (XPRMArray) mod.FindIdentifier("x");
      // Get the number of dimensions of the array
      dim = varr.Dim;
      // Get the indexing sets
      sets = varr.IndexSets;
      // We could use varr.ToString() to print out a summary of the
      // array contents, but instead we'll demonstrate how to iterate
      // over the array contents directly
      Console.WriteLine("\n1. Logic entries:");
      // Get the first entry of varr
      foreach(int[] indices in varr.Indices) {
        Console.Write("x(");
        // Get the values for this index
        vindex = varr.DereferenceIndex(indices);
        // Now, output them.  Note that we could call the utility method
        // varr.IndexToString(indices) instead of this and the previous
        // line
        for (int i=0;i<dim-1;i++)
          Console.Write(vindex[i] + ",");
        Console.Write(vindex[dim-1] + "), ");
      };
      // Now enumerate over the true entries - in a dense array this would
      // be no different from the previous method, so skip it in this case.
      if (varr.IsDynamic) {
        Console.WriteLine("\n\n2. True entries:");
        foreach(int[] indices in varr.TEIndices) {
          Console.Write("x(");
          vindex = varr.DereferenceIndex(indices);
          for (int i=0;i<dim-1;i++)
            Console.Write(vindex[i] + ",");
          Console.Write(vindex[dim-1] + "), ");
        };
      }
      Console.WriteLine();
      mod.Reset();
    }
  }
 }
 | 
| 
 | 
| mmexas-cs/mmexas.csproj | 
| <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="../Models/**" CopyToOutputDirectory="Always" LinkBase="Models" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="FICO.Xpress.XPRMdn" Version="5.6.1" /> 
  </ItemGroup>
  
</Project> | 
| 
 | 
| mmexlst-cs/mmexlst.cs | 
| /********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexlst.cs                                     */
/*  ```````````````                                     */
/*  Accessing modeling objects                          */
/* (enumerating the elements of a list)                 */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: J. Farmer                               */
/********************************************************/
using System;
using System.IO;
using Mosel;
namespace mmexlst {
  /// <summary>
  /// Records example
  /// </summary>
  class mmexlstClass {
    [STAThread]
    static void Main(string[] args) {
      
      /* Initialize Mosel */
      XPRM mosel = XPRM.Init();
      // Set Mosel work directory to folder containing our example source code
      mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;
      
      /* Compile & load the model */
      mosel.Compile("Models/euler.mos");
      XPRMModel mod = mosel.CompileAndLoad("Models/euler.mos");
      
      /* Run the model */
      mod.Run();
      
      /* Get the model object named 'TOUR' */
      XPRMList lst = (XPRMList) mod.FindIdentifier("TOUR");
      
      /* Print out all the list elements */
      Console.Write("Tour: ");
      int count=0;
      foreach (XPRMValue val in lst) {
        Console.Write(val.AsInteger());
        if ((++count)<lst.Count)
          Console.Write(" -> ");
      }
      Console.WriteLine();
      
    }
  }
} | 
| 
 | 
| mmexlst-cs/mmexlst.csproj | 
| <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="../Models/**" CopyToOutputDirectory="Always" LinkBase="Models" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="FICO.Xpress.XPRMdn" Version="5.6.1" /> 
  </ItemGroup>
  
</Project> | 
| 
 | 
| mmexrec-cs/mmexrec.cs | 
| /********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexrec.cs                                     */
/*  ```````````````                                     */
/*  Accessing modeling objects                          */
/* (enumerating an array of records and                 */
/*  printing the value of each record field).           */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: J. Farmer                               */
/********************************************************/
using System;
using System.IO;
using Mosel;
namespace mmexrec {
  /// <summary>
  /// Records example
  /// </summary>
  class mmexrecClass {
    [STAThread]
    static void Main(string[] args) {
      
      /* Initialize Mosel */
      XPRM mosel = XPRM.Init();
      // Set Mosel work directory to folder containing our example source code
      mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;
      
      /* Compile & load the model */
      mosel.Compile("Models/burglar_rec.mos");
      XPRMModel mod = mosel.LoadModel("Models/burglar_rec.bim");
      
      /* Run the model */
      mod.Run();
      
      /* Get the model object named 'I' */
      XPRMArray arr = (XPRMArray) mod.Identifiers["I"];
      /* Iterate over the fields */
      XPRMRecordFields fields = ((XPRMUserType)mod.ExpandType(arr.TypeCode)).Fields;
      
      Console.WriteLine("Record has {0} fields:", fields.Count);
      foreach (XPRMRecordField f in fields)
        Console.WriteLine(f.Name);
      
      /* Enumerate the array (we know it has a single dimension) */
      XPRMSet[] indSets = arr.IndexSets;
      
      /* Get the first index tuple */
      int[] indices = arr.FirstIndex;
      do {
        /* Display the array index */
        Console.Write("I({0}): \t", indSets[0].Get(indices[0]));
        /* Retrieve the array entry (=record) */
        XPRMRecord rec = arr.Get(indices).AsRecord();
        /* Output contents of 1st record field */
        Console.Write("{0}={1} ", fields[0].Name, rec.GetValueAsReal(fields[0]));
        /* Output contents of 2nd record field */
        Console.Write("{0}={1} ", fields[1].Name, rec.GetValueAsReal(fields[1]));
        Console.WriteLine();
      } while (arr.NextIndex(indices)); /* And move onto the next index tuple */
      
      
      /* Reset the model */
      mod.Reset();
      
    }
  }
} | 
| 
 | 
| mmexrec-cs/mmexrec.csproj | 
| <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="../Models/**" CopyToOutputDirectory="Always" LinkBase="Models" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="FICO.Xpress.XPRMdn" Version="5.6.1" /> 
  </ItemGroup>
  
</Project> | 
| 
 | 
| mmexprob-cs/mmexprob.cs | 
| /********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexprob.cs                                    */
/*  ````````````````                                    */
/*  Example for the use of the Mosel libraries          */
/*  (accessing problems and solution information)       */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: J.Farmer & S. Heipcke                   */
/********************************************************/
using System;
using System.IO;
using Mosel;
namespace mmexprob {
  public class mmexprobClass {
    /// <summary>
    /// Main entry point for the application
    /// </summary>
    [STAThread]
    static void Main(string[] args) {
      XPRM mosel;
      XPRMModel mod;
      XPRMArray varr, darr;
      XPRMLinCtr lgrade;
      // Initialize Mosel
      mosel = XPRM.Init();
      // Set Mosel work directory to folder containing our example source code
      mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;
      // Compile and load a model file
      mod = mosel.CompileAndLoad("Models/blend2.mos");
      // Run the model (it includes optimization)
      mod.Run();
      // Export the problem to a file in LP format (maximization)
      mod.ExportProblem("p", "blend");
      // Test whether optimal is found
      if (mod.ProblemStatus==XPRMProblemStatus.PB_OPTIMAL)
        Console.WriteLine("Solution is optimal.");
      // Print out the objective function value
      Console.WriteLine("Objective value: {0}", mod.ObjectiveValue);
      // Get the model objects 'x' and 'COST' (both arrays)
      varr = (XPRMArray) mod.FindIdentifier("x");
      darr = (XPRMArray) mod.FindIdentifier("COST");
      // For each entry in array varr, display solution value and
      // corresponding cost
      foreach(int[] indices in varr.Indices) {
        Console.WriteLine(
          "x{0}={1} (COST: {2})",
          varr.IndexToString(indices),
          varr.Get(indices).AsMPVar().Solution,
          darr.GetAsReal(indices)
        );
      }
      // Get the model object 'LoGrade'
      // It must be a reference to a linear constraint
      lgrade = ((XPRMReference) mod.FindIdentifier("LoGrade")).Value.AsLinCtr();
      Console.WriteLine(
        "LoGrade: activity={0}, dual={1}",
        lgrade.Activity,
        lgrade.Dual
      );
      mod.Reset();
    }
  }
}
 | 
| 
 | 
| mmexprob-cs/mmexprob.csproj | 
| <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="../Models/**" CopyToOutputDirectory="Always" LinkBase="Models" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="FICO.Xpress.XPRMdn" Version="5.6.1" /> 
  </ItemGroup>
  
</Project> | 
| 
 |