www.fico.com
Makeeverydecisioncount
TM
Moseltipsandtricks
Lastupdate25February,2013
Pdf user password - C# PDF Password Library: add, remove, edit PDF file password in C#.net, ASP.NET, MVC, WinForms, WPF
Help to Improve the Security of Your PDF Document by Setting Password
add password to pdf online; break pdf password online
Pdf user password - VB.NET PDF Password Library: add, remove, edit PDF file password in vb.net, ASP.NET, MVC, WinForms, WPF
Help to Improve the Security of Your PDF Document by Setting Password
add password to pdf without acrobat; add copy protection pdf
NewandlessknownfeaturesofMosel
• Selectednewfeatures
– Addingafiletoatararchive(newinRel7.3)
– Addingatimestampintoafilename(newinRel7.3)
– Texthandling:Howandwheretousethetype
text
(modulemmsystem)
• Structuringmodels
– Usingincludeandpackages
– Paths:getcwd,runtimeparameters,DSOsearchpath
– Advanceddatastructures:records,lists
• Andalso:
– Modelingtricks:Counters,indicatorsandlogicalconstraints,dotnotation,dates
andtimes
– DeploymentviaanExcelVBmacro
– Outputredirection
WorkingwithTARarchives
Tip1:AddingafiletoacompressedTARarchive
declarations
lsf: list of text
origfname: text
end-declarations
makedir(gettmpdir+"/tartemp")
! Create temporary directory
if getfstat(archivename)<>then
! Untar if archive exists
untar("zlib.gzip:"+archivename, gettmpdir+"/tartemp")
end-if
! Copy file to temporary y directory
origfname:=pathsplit(SYS_FNAME,filetoadd)
fcopy(filetoadd, ":"+ gettmpdir+"/tartemp/"+origfname)
! Rebuild the archive
findfiles(SYS_RECURS, lsf, gettmpdir+"/tartemp""*")
newtar(0"zlib.gzip:"+archivename, gettmpdir+"/tartemp", lsf)
removefiles(SYS_RECURS, gettmpdir+"/tartemp""*")
removedir(gettmpdir+"/tartemp")
! Delete temporary files
Timestamp
Tip2:Insertingatimestampintoafilename
public procedure addtimestamp(filestochange: set of string)
declarations
origdir, origfname, , origextn, timestmp: : text
end-declarations
! Create a time stamp - redefining datetime e format as s to avoid d use
! of ’:’ to prevent interpretation as I/O driver
usedfmt:=getparam("datetimefmt")
! Save present t format
setparam("datetimefmt""%0d%0m%0yT%0H.%0M.%0S")
timestmp:= text(datetime(SYS_NOW))
setparam("datetimefmt", usedfmt)
! Reset to previous format
! Rename all l files s to include the time stamp in their name
forall(f in filestochange) do
origdir:=pathsplit(SYS_DIR,f)
origfname:=pathsplit(SYS_FNAME,f)
origextn:=pathsplit(SYS_EXTN,origfname,origfname)
fmove(f, origdir r + "/" + origfname + "-"+timestmp +"." +origextn)
end-do
end-procedure
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page1
C# PDF File Permission Library: add, remove, update PDF file
RootPath + "\\" 3.pdf"; String outputFilePath = Program.RootPath + "\\" 3_pw_a.pdf"; // Create a password setting object with user password "Hello World
create password protected pdf online; convert protected pdf to word
VB.NET PDF File Permission Library: add, remove, update PDF file
3.pdf" Dim outputFilePath As String = Program.RootPath + "\\" 3_pw_a.pdf" ' Create a password setting object with user password "Hello World".
pdf owner password; convert protected pdf to word online
Thetype’text’
Tip3:Howandwheretousethetype
text
• Thetypetextisdefinedinmodulemmsystem
– maybegeneratedfromallobjectsthatcanbeconvertedtoatext
– supportstheusualstringoperations(concatenation,formatting
txtfmt
)
uses "mmsystem"
declarations
t: text
end-declarations
t:= "a text"
inserttext(t, "short "3)
! => > t t = = ’a short text’
writeln("_"*80)
! Draw a a line e of f 80 characters
text
vs.
string
– every
string
objectinamodelisenteredinthenamesdictionary,
text
objectsare
notsaved
⇒use
string
forindexation,use
text
whenevermanipulatingtexts
– textobjectscanbealtered(e.g.changingasequenceofcharactersinatext),strings
cannot
text
supportswidersetofoperations(likeinsertion,deletion,removingtrailing
blanks,searchofsubstrings)than
string
– implicitconversionfrom
string
to
text
(butnotthereverse):aroutineexpecting
atextasparametermaybeusedwithastringinstead
StructuringMoselmodels
Tip4:Workingwithpackages
• Package=MosellibrarywrittenintheMosellanguage(asopposedtoMoselmodules
thatareimplementedinC)
– similarstructureasmodels,keyword
model
isreplacedby
package
– includedwiththe
uses
statement
– compileinthesamewayasMoselmodels,placeBIMonDSOsearchpath
– packagename=nameoftheBIMfile(package.bim)
– definitionofnewsubroutines,constants,andtypes
• Alternativetopackages:
include
insertscontentsintoamodeltobecompiledwiththe
model
• File
toolbox.mos
(compileto
toolbox.bim
)
package toolbox
uses "mmsystem"
version 12.08.30
public procedure addtimestamp(filestochange: set of string)
...
end-procedure
! Overloaded version with different arguments
public procedure addtimestamp(filetochange: string)
addtimestamp({filetochange})
end-procedure
end-package
• UsepackageinaMoselmodel:
uses "toolbox"
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page2
VB.NET PDF Converter Library SDK to convert PDF to other file
It provides user with efficient .NET solution which can help user achieve high-quality and fast PDF to image conversion using VB.NET code.
pdf open password; adding a password to a pdf
C# HTML5 PDF Viewer SDK to view, annotate, create and convert PDF
Except password setting, RasterEdge HTML5 PDF Editor also enable C#.NET users to perform more actions to set PDF file C#.NET user can redact PDF text, PDF
convert password protected pdf to excel online; adding password to pdf file
Tip5:Packagedependencies
• Apackagecannotbeimportedseveraltimesbyamodelandpackagespublishsymbols
ofpackagestheyuse
– example:ifpackageP1importspackageP2,thenamodelusingP1cannotimport
explicitlyP2(with
uses
)buthasaccesstothefunctionalityofP2viaP1.
• Requirements=symbolsapackagerequiresforitsprocessingbutdoesnotdefine
– thesymbolsmustbedefinedeitherinthemodelorinanotherpackage(butnotin
amodule)
requirements
blocksareaspecialkindofdeclarationblocksinwhichconstants
arenotallowedbutprocedure/functionscanbedeclared
• PackageP1:
uses "P2"
! Load d package e P2
declarations
public myct: integer
end-declarations
procedure dosomething(txt: text)
writeln(calcvalue(txt))
! Call l function n from P2
end-procedure
• PackageP2:
requirements
myct: integer
procedure dosomething(txt: text)
! Can now use subroutine from P1
end-requirements
function calcvalue(txt: text): integer
myct += 1
! Use a symbol defined in n P1
returned:= ...
FileandDSOpaths
Tip6:PathsinMoselmodels
• FilesreferredtoinMoselmodelswillbesoughtrelativetothecurrentworkingdirectory
(cwd)
– cwdvariesdependinghowtheapplicationisstartedup
– retrievecwdwith
getcwd
or
getparam("work_dir")
– cwdcanbechangedwith
setparam("work_dir", mynewdir)
– defaultcwdcanberedefinedbycallingapplicationwith
XPRMsetdefworkdir
• ⇒Useabsolutepathsorprovideapathrootviaamodelparameterforallfilestoavoid
problems
parameters
DIR="./"
FILENAME="mydata.xls"
end-parameters
setparam("work_dir", getparam("tmpdir")) ! Set Mosel’s temp. dir. as cwd
writeln(getcwd)
! Display new cwd
initializations from "mmsheet.xls:"+DIR+FILENAME
...
end-initializations
fopen(DIR+"log.txt", F_OUTPUT+F_APPEND)
! Redirect output to file
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page3
VB.NET PDF: Get Started with PDF Library
Document Protect. Password: Set File Permissions. Password: Open Document. Edit Digital Help VB.NET User Have Quick Evaluation of .NET PDF SDK with
add password to pdf file without acrobat; convert password protected pdf to excel
VB.NET Image: How to Draw Annotation on Doc Images with Image SDK
gif, tiff and bmp) or documents (like multi-page TIFF, Microsoft Office Word and PDF file). This VB.NET image annotation library SDK is very user-friendly in
password on pdf file; convert protected pdf to word document
Tip7:DSOsearchpaths
• DSOsandpackagesoftheMoseldistributionarefoundautomaticallyifthefullXpress
installationprocessfollowed
• AdditionalDSOorpackagelocationscanbespecifiedbysettingtheenvironment
variable
MOSEL_DSO
• CanalsosetDSOdirectoryatruntimeusing
XPRMsetdsopath
(incallingapplication)or
inthecallingmodel(settingdoesnotapplytothemodelitself!)
! Set MOSEL_DSO to the default location of DSOs
setenv("MOSEL_DSO", getenv("XPRESSDIR") + "/dso")
Advanceddatastructures
Tip8:Advanceddatastructures:lists
• List=collectionofobjectsofthesametype
• Alistmaycontainthesameelementseveraltimes
• Theorderofthelistelementsisspecifiedbyconstruction
declarations
L: list of integer
M: array(rangeof list of string
end-declarations
L:= [1,2,3,4,5]
M:: (2..4)[[’A’,’B’,’C’], [’D’,’E’], , [’F’,’G’,’H’,’I’]]
L2:= gethead(L,3)
! => L2=[1,2,3]
reverse(L)
! => L=[5,4,3,2,1]
cuttail(L,2)
! => L=[5,4,3]
Tip9:Advanceddatastructures:records
• Record=finitecollectionofobjectsofanytype
• Eachcomponentofarecordiscalledafieldandischaracterizedbyitsnameanditstype
declarations
arc = record
Source,Sink: string
! Source and sink of arc
Cost: real
! Cost coefficient
end-record
ARC: array(ARCSET:rangeof arc
end-declarations
ARC(1).Source:= "B"
ARC(3).Cost:= 1.5
writeln(ARC(1))
! => [Source=’B’ Sink=’’ Cost=0]
Counters
Tip10:Counters:using
count
• Theaggregateoperator
count
returnsthenumberoftimesthatatestsucceeds
declarations
L: list of string
end-declarations
L:= [’a’’ab’’abc’’da’’bc’’db’]
writeln("Occurences of ’b’ in L: : ",
count(s in L | findtext(s, ’b’1)>0) )
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page4
C# PDF File Merge Library: Merge, append PDF files in C#.net, ASP.
input PDF documents can be merged and appended together according to its loading sequence, and then saved and output as a single PDF with user-defined location
annotate protected pdf; break a pdf password
VB.NET PDF Convert to HTML SDK: Convert PDF to html files in vb.
edited), is less searchable for search engines. The other is the crashing problem when user is visiting the PDF file using web browser.
create password protected pdf; add password to pdf reader
Tip11:Counters:using
as counter
• Usetheconstruct
as counter
tospecifyacountervariableinaboundedloop(i.e.,
forall
oraggregateoperatorssuchas
sum
):ateachiteration,thecounteris
incremented
S:= {158-1472}
cnt:=0.0
writeln("Number of f odd d numbers in S: ", count(i in S | isodd(i)) )
writeln("Average of odd numbers in S: : ",
(sum(cnt as counter, i in S | | isodd(i)) ) i) / cnt)
Indicatorandlogicalconstraints
Tip12:Indicatorconstraints
• Indicatorconstraint=globalentitythatassociatesabinaryvariablebwithalinear
constraintC
– modelsanimplication:
’ifb=1thenC’,insymbols:b→C,or
’ifb=0thenC’,insymbols:
¯
b→C
(theconstraintCisactiveonlyiftheconditionistrue)
• ⇒Useindicatorconstraintsfortheformulationoflogicexpressionsintheplaceof
big-Mconstructs
Tip12:IndicatorconstraintsinMosel
• Needabinaryvariable(type
mpvar
)andalinearinequalityconstraint(type
linctr
)
• Specifythetypeoftheimplication(1forb→Cand-1for
¯
b→C)
• Thesubroutine
indicator
returnsanewconstraintoftype
logctr
thatcanbeusedin
thecompositionofotherlogicexpressions
uses "mmxprs"
declarations
C: linctr
L: logctr
x1, x2, b: mpvar
end-declarations
is_binary
! Variable for indicator r constraints
C:= x2<=5
L:= indicator(1, b, x1+x2>=12)
! b=1 1 -> > x1+x2>=12
indicator(-1, b, , C)
! b=0 0 -> > x2<=5
C:=0
! Delete auxiliary constraint definition
Tip13:Logicconstructs
• Packageadvmoddefinestype
logctr
fordefiningandworkingwithlogicconstraintsin
MIPmodels
• Implementationoftheseconstraintsisbasedonindicatorconstraints
• Buildlogicconstraintswithlinearconstraintsusingtheoperations
and
,
or
,
xor
,
implies
,and
not
• Mustincludethepackage
advmod
insteadoftheOptimizerlibrary
mmxprs
uses "advmod"
declarations
x: array(1..3of mpvar
end-declarations
implies(x(1)>=10, x(1)+x(2)>=12 and not x(2)<=5)
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page5
declarations
p: array(R) of mpvar
end-declarations
forall(i in R) p(i) is_binary
! Choose at least one of projects s 1,2,3 3 (option A)
! or at t least t two of projects 2,4,5,6 (option n B)
p(1) + p(2) + p(3) >= 1 or p(2) + + p(4) + p(5) + p(6) >= 2
! Choose either option A or option B, but not t both
xor(p(1) + p(2) + + p(3) >= 1, p(2) + p(4) + p(5) + p(6) >= 2)
DeploymentviaanExcelVBmacro
Tip14:DeploymentviaanExcelVBmacro
• GenerateVBcodeusingtheIVEdeploymentwizzard
– menuDeployDeploy...,selectVisualBasic,thenconfirmwithNext
– copythedisplayedVBcodeintotheclipboard
• GeneratetheBIMfile
• Createamacro-enabledspreadsheet(.xlsm)
• SelectExcelmenuDeveloperInsert
– selectthebuttonobjectandpositionitusingthemouse
– assignanewmacrotothebuttonandpastetheVBcodefromclipboardintothe
macro
• UsingExcelmenuDeveloperVisualBasicFileImportFile...add
xprm.bas
from
the
include
subdirectoryofXpresstotheproject
• Selectthebuttonwithrightmousekeytoedititstext
• IfyoudonotseetheDevelopermenu:
– Excel2007:clickontheroundbuttontopleft
thenselectExcelOptions;under
thePopularsection,checktheoptionShowDevelopertab
– Excel2010:ontheFiletab,chooseOptions,thenchooseCustomizeRibbonandin
thelistofMainTabs,selecttheDevelopercheckbox:
– anewtaboftheribbonmenuwillappearwithaVBAoption
• Outputredirectiontospreadsheet:
– DefineacellrangeOutput
(Excel2010:selectthedesiredareawithyoumouse,thenusethemenuFormulas
DefineNametoentertherangename)
– Editthemacro(afterXPRMinit):
Call XPRMsetdefstream(0, XPRM_F_WRITE, , XPRM_IO_CB(AddressOf OutputCB))
...
Public Function OutputCB(ByVal model l As s Long, ByVal info As Long,
ByVal msg g As String, ByVal size As Long) As s Long
’ Process windows messages so Excel GUI responds
DoEvents
’ Strip the extra newline character and print to sheet
Range("Output").Cells(11) = = Mid(msg, 1Len(msg) ) - 1)
End Function
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page6
Outputredirection
Tip15:Outputredirection
• RedirectionwithinaMoselmodel:
! tee: Dedouble output to file + default output (screen)
fopen("tee:mylogfile.txt&", F_OUTPUT+F_APPEND)
writeln(...)
fclose(F_OUTPUT)
• Redirectstreamsforsubmodelsfrommastermodel(correspondinglibraryfunction
XPRMsetdefstream
):
! null: Discard all output; tmp: Mosel’s temporary directory
setdefstream("mysubmod.mos", F_OUTPUT, "null:")
setdefstream("mysubmod.mos", F_ERROR, "tmp:errlog.txt")
Datesandtimes
Tip16:Datesandtimes
• mmsystemdefinestypes
date
,
time
,and
datetime
forhandlingdateandtimetypes
– conversionto/fromnumericalvalues,e.g.,foruseasindices(
getasnumber
)
• Dataconnectormodulesmmsheet,mmodbcandmmocisupportthesetypesforreading
andwritingdata
– representationofdateandtimeinformationwithindatabasesisdifferentfromone
producttoanotherandmaynotbecompatiblewithMosel’sdefaultformat⇒
adaptformatsettings
declarations
d: integer
T: time
Dates: array(1..5of date
end-declarations
writeln(datetime(SYS_NOW))
! Datetime e returned by system
setparam("timefmt""%0H:%0M:%0S"! Set t new time format
setparam("datefmt""%y-%0m-%0d")
! Set t new date format
! Convert date e created d from string to number (JDN)
d:= getasnumber(date("2012-12-25")))
initializations from "mmodbc.odbc:datetime.mdb"
as "Time1"
Dates as "noindex;Dates"
end-initializations
Tip17:Calculatingthecalendarweeknumber
• Function
getweek
belowreturnsthecalendarweekcountforagivendate.
– implementation:
getasnumber
calculatestheJuliandaynumberand
getweekday
returnstheweekdaynumberforadate
– usage:
wnum:= getweek(date(2012,2,29))
function getweek(d:date): integer
firstday:=date(getyear(d-getweekday(d)+4),1,3)
returned:= (getasnumber(d) - getasnumber(firstday) +
getweekday(firstday+1)+5div 7
end-function
cCopyright2001–2013FairIsaacCorporation.Allrightsreserved.
page7
Lower/uppercaseconversions
Tip18:Howtoconvertatextintolower(upper)case
• Note:ThefollowingroutinesupposesASCIIencoding
! Turn upper case letters into lower case
public function makelowercase(t: text): : text
returned:=t
forall(i in 1..t.size) do
v:=getchar(t,i)
if (v>=65 and v<=90then
! lower to upper:
v>=97 and d v<=122
setchar(returned, i, v+32)
! lower to upper:
v-32
end-if
end-do
end-function
! Overloaded version for ’string’
public function makelowercase(t: string): string
returned:=string(makelowercase(text(t)))
end-function
SpreadsheetIOdrivers
Tip19:Comparisonofspreadsheetdrivers
excel
xsl/xslx
csv
File type
physical file
physical file
extended file
Supported platforms
Windows
Windows, Linux, Mac all Xpress platforms
Requirements
Excel+ open inter-
active session
none, can be used
remotely
none, can be used
remotely
File creation for output
no
yes
yes
Output writing mecha-
nism
on-screen display
without saving if
application
run-
ning,
otherwise
data saved into
file
data saved into
file
data saved into
file
Named ranges
yes
yes
no
Multiple worksheets
yes
yes
no
VB Macros
yes
yes
no
Parameters
Tip 20: Accessing parameters with bitmap format
• Parameters that are encoded as bitmaps are accessed as integers
• The Mosel function
bittest
checks whether a bit is set
! Turn on bits 0, 1, and 4, all else off (2^0 + 2^1 + 2^4 = 1+2+16 = 19)
setparam("XPRS_HEURSEARCHTREESELECT",19)
! Modify the current setting: turn off bit 5 (2^5 = 32)
presolveops:= getparam("XPRS_PRESOLVEOPS")
if bittest(presolveops,32)=32 then presolveops-=32; end-if
setparam("XPRS_PRESOLVEOPS", presolveops)
! The value of a signed integer with all bits equal to 1 is -1
setparam("XPRS_CUTSELECT"-1)
! Enable all features
setparam("XPRS_CUTSELECT"-8193)
! All except bit 13 (-1 -2^13 = -8193)
cCopyright 2001–2013 Fair Isaac Corporation. All rights reserved.
page8
Using ’assert’
Tip 21: Using
assert
to validate input data
• The
assert
statement serves for checking input data (including model parameters) for
correct types and values
– by default,
assert
is only executed for models compiled in debug mode (flages ’g’
or ’G’), this behaviour is changed by specifying option
keepassert
– the default error code returned by ’assert’ is 8, an alternative value can be specified
as the optional third argument
options keepassert
! Always apply ’assert’
parameters
A=10
DATAFILE="mydata.dat"
end-parameters
assert(A in 1..20"Wrong parameter r value")
(! Same as:
if A not in 1..20 then
writeln("Wrong parameter value")
exit(8)
end-if
!)
! If file not found, return exit code 5
assert(getfstat(DATAFILE)=0"Data file not found"5)
cCopyright 2001–2013 Fair Isaac Corporation. All rights reserved.
page9
Documents you may be interested
Documents you may be interested