Initializing help system before first use

Using the Shared Database

All Xpress components (Insight, Workbench, and Executor) deployed in the same solution at the same lifecycle stage will share this solution database. This example develops the Burglar example used in the Mosel guide to store VALUE and WEIGHTS input arrays in the database during load, and read them from there during run.

To connect to the solution database, your model must use the trusteddsn module and then call the procedure trusteddsninit. This will allow the model to connect to the special ODBC data-source named customdb which represents the shared database.

Xpress Executor code sample
(!
    Example of using shared database.
    This is a variant of the Burglar example where the item values and weights are stored in the database.
    (c) 2019 Fair Isaac Corporation.
!)
model "burglar_with_solution_db"
  options keepassert
  uses "trusteddsn","mmodbc","mmxprs"

  parameters
    ! Whether to reset solution database at the start of the model
    RESET_SOLDB=false
  end-parameters

  ! **** Declare public data **** !
  declarations
    ! Maximum weight alowed for haul
    WTMAX: integer
    ! Index range for items
    Items=1..8

    x: array(Items) of mpvar

    VALUE: array(Items) of real
    WEIGHT: array(Items) of real
  end-declarations

  ! *** Allow connection to the solution database *** !
  trusteddsninit
  ! *** Connect to solution database *** !
  SQLconnect("DSN=customdb")
  assert(getparam("SQLsuccess"))

  ! *** Optionally, reset solution datbase to default items *** !
  if RESET_SOLDB then
    ! *** Create solution database *** !
    SQLexecute("CREATE TABLE IF NOT EXISTS Items (item INTEGER NOT NULL PRIMARY KEY, value DOUBLE NOT NULL, weight DOUBLE NOT NULL)")
    assert(getparam("SQLsuccess"))

    ! *** Populate solution database *** !
    ! Note: this deletes everything in the solution database - this is okay for the purpose of the example, probably not what you want to do
    ! in your actual model.
    SQLexecute("DELETE FROM Items")
    assert(getparam("SQLsuccess"))

    VALUE :: [15,100, 90, 60, 40, 15, 10,  1]
    WEIGHT:: [ 2, 20, 20, 30, 40, 30, 60, 10]
    SQLexecute("INSERT INTO Items (item,value,weight) VALUES (?,?,?)", [VALUE, WEIGHT])
    assert(getparam("SQLsuccess"))
  end-if

  ! *** Set the maximum weight - in a real model, this would be input data read from a file *** !
  WTMAX := 102

  ! *** Load data from the shared database *** !
  SQLexecute("SELECT item, value, weight FROM items", [VALUE, WEIGHT])
  assert(getparam("SQLsuccess"))

  ! *** Construct the model *** !
  MaxVal:= sum(i in Items) VALUE(i)*x(i)  ! Objective: maximize total value

  ! Weight restriction
  WtMax:= sum(i in Items) WEIGHT(i)*x(i) <= WTMAX

  forall(i in Items) x(i) is_binary  ! All x are 0/1

  ! *** Solve the problem *** !
  maximize(MaxVal)

  ! *** Print out the solution *** !
  writeln("Solution:\n Objective: ", getobjval)
  forall(i in Items)  writeln(" x(", i, "): ", x(i).sol)
end-model

© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.