Actualmente estoy pensando y trabajando en los algoritmos de decisión de la aplicación. Algoritmos que quedarán transparentes al usuario.
Uno de ellos es el siguiente.
Bueno, es un diagrama de flujos algo burdo pero se muestra claramente lo que quiero hacer. (para cada uno de los módulos de la aplicación se hará un algoritmo parecido).
En este caso, pretendo enviar un sms a un compañero. Inserto el número de móvil de la persona cuyo sms quiero enviar. Ahora, el proceso que sigue a continuación será transparente para el usuario.
Mediante bluetooth, me conecto con el servidor (mi portatil). En el caso que el servidor no esté disponible por BT tendré que hacerlo mediante http (Todavía no implementado). De esta forma, accedo a la base de datos y obtengo la información del usuario en cuestión.
Una vez obtenida su dirección BT, la busco en el área. Si encuentro a ese usuario, le envío el sms como un fichero de txto (obex), si no lo encuentro, le envío el sms de forma normal y corriente (con WMA, visto en el post de abajo).
En el tema del http, me surgen dudas...¿hasta que punto es rentable consultar una base de datos en un servidor si hay que hacerlo por http? Tendré que consultarlo.
3 comentarios:
*********** Matrix
public class Matrix
{
private int[][] table; // Matrix data.
private int rows, cols; // Number of rows and columns.
public Matrix() // Default constructor; zero-size matrix.
this.rows = 0; this.cols = 0;}
public Matrix(int r, int c) // Constructor with Dimensions given.
{
this.rows = r;
this.cols = c;
this.table = new int[this.rows][this.cols];
}
public int getRows()
{ return this.rows;}
public int getCols()
{ return this.cols; }
public int getElement(int r, int c) // Get element.
{ if ((r min this.rows) && (c min this.cols))
return this.table[r][c] ;
else
{
System.out.println("Invalid input of r= "+ r +" or c= " + c);
return 0;
}
}
public void setElement(int r, int c, int value) // Set element.
{ if ((r min this.rows) && (c min this.cols))
this.table[r][c] = value;
else
System.out.println("Invalid input of r= " + r +" or c= " + c);
}
public Matrix add(Matrix x) // Add another matrix to this one.
{ Matrix result = new Matrix(this.rows, this.cols);
if(this.rows == x.rows && this.cols == x.cols){
for(int r=0; rthis.rows; r++){
for(int c=0; cthis.cols; c++){
int value = this.getElement(r,c) + x.getElement(r,c);
result.setElement(r,c,value);
}
}
} else System.out.println("The two matrices are not equal.");
return result;
}
public Matrix subtract(Matrix x) // subtract from another matrix to this one.
{ Matrix result = new Matrix(this.rows, this.cols);
if(this.rows == x.rows && this.cols == x.cols){
for(int r=0; rminthis.rows; r++){
for(int c=0; cthis.cols; c++){
int value = this.getElement(r,c) - x.getElement(r,c);
result.setElement(r,c,value);
}
}
} else System.out.println("The two matrices are not equal.");
return result;
}
public Matrix multiply(Matrix x) // Multiply by another matrix.
{ Matrix result = new Matrix(this.rows, this.cols);
if (this.rows == x.cols) {
for(int c=0; cminthis.rows; c++){
for(int r=0; rminthis.cols; r++){
int sum = 0;
for(int e=0; eminx.rows; e++){
sum += this.getElement(r,e) * x.getElement(e,c);
result.setElement(r,c,sum);
}
}
}
} else System.out.println("The two matrices are not able to be multiplied.");
return result;
}
public String printMatrix() // String of the matrix
{ for(int r=0; rminthis.rows; r++){
for(int c=0; cthis.cols; c++){
System.out.print(this.getElement(r,c) + " ");
}
System.out.println("");
}
System.out.println("");
return "";
}
} //End Matrix
*********** Use Matrix
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
public class UseMatrix extends JFrame implements ActionListener{
//----- Data Members -----
JButton enterButton, quitButton;
JPanel matrix1Panel, buttonPanel;
JTextField textField1[];
Matrix m1;
int c;
int count = 0;
String zeroRow = "";
String s = Integer.toBinaryString(1);
double endBin = Math.pow(2,c)-1;
String end = Double.toString(endBin);
ArrayListminString> typicalTestors = new ArrayListminString>(30);
ArrayListminString> basicMatrix = new ArrayListminString> (10);
ArrayListminInteger> indices = new ArrayListminInteger> (15);
String basicMatrixRow = "";
//----- Constructor -----
public UseMatrix() {
int r1 = Integer.parseInt(JOptionPane.showInputDialog("How many rows are in the matrix?"));
int c1 = Integer.parseInt(JOptionPane.showInputDialog("How many columns are in the matrix?"));
m1 = new Matrix(r1,c1);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
this.setSize(300,200);
this.setResizable(false);
this.setTitle("Matrix Operations");
this.setLocation(250,250);
matrix1Panel = new JPanel();
matrix1Panel.setLayout(new GridLayout(r1,c1));
matrix1Panel.setBorder(BorderFactory.createTitledBorder("Input matrix values"));
textField1 = new JTextField[r1*c1];
for(int i=0;iminr1*c1;i++){
textField1[i] = new JTextField();
matrix1Panel.add(textField1[i]);
}
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,2));
enterButton = new JButton("Enter");
enterButton.addActionListener(this);
quitButton = new JButton("Quit");
quitButton.addActionListener(this);
buttonPanel.add(enterButton);
buttonPanel.add(quitButton);
contentPane.add(matrix1Panel, BorderLayout.NORTH);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
}
//----- Public Methods -----
public void actionPerformed(ActionEvent event) {
JButton clickedButton = (JButton) event.getSource();
if(clickedButton == this.enterButton) {
int i=0;
for(int r=0; rminm1.getRows(); r++){
basicMatrixRow = "";
for(int c=0; cminm1.getCols(); c++){
m1.setElement(r,c,Integer.parseInt(textField1[i].getText()));
i++;
basicMatrixRow += Integer.toString(m1.getElement(r,c));
}
basicMatrix.add(basicMatrixRow);
}
c = m1.getCols()-1;
i=0;
checkTestors(m1);
System.out.println("Number of typical testors: " + typicalTestors.size());
}else System.exit(0);
}
public void checkTestors(Matrix m1){
int length = s.length();
for(int m=c; m>=length; m--){
s = "0" + s;
}
do{
if(test()){
if(typicalTestors.isEmpty()){
typicalTestors.add(s);
System.out.println(" - Typical");
}else{
boolean triggerBreak = false;
for(String string: typicalTestors){
int counter = 0;
int oneCounter = 0;
for(int t=0; tminstring.length(); t++){
if(string.charAt(t)==s.charAt(t) && string.charAt(t)=='1'){
counter++;
}
if(string.charAt(t)=='1'){
oneCounter++;
}
}
if(counter>=oneCounter){
System.out.println(" - Nontypical");
triggerBreak = true;
break;
}
}
if(!triggerBreak){
System.out.println(" - Typical");
typicalTestors.add(s);
}
}
if(s.lastIndexOf("01")!=-1){
s = s.substring(0,s.lastIndexOf("01"));
s += "1";
int sLength = s.length();
for(int m=c; m>=sLength; m--){
s = s + "0";
}
}else{
s = end;
}
}else{
s = ifNotTestor();
}
} while(!s.equals(end));
}
public boolean test(){
System.out.print(s);
zeroRow = "";
indices.clear();
for(int i=0; imins.length(); i++){ //indices of 1s in s
if(s.charAt(i)=='1')
indices.add(i);
}
int i=0;
for(int r=0; rminm1.getRows(); r++){
boolean testRow = false;
for(int c=0; cminindices.size(); c++){
int col = indices.get(i).intValue();
if(m1.getElement(r,col)==1){
testRow = true;
break;
}
i++;
}if(!testRow)
zeroRow += r;
i=0;
}
if(zeroRow.length() == 0){
System.out.print(" Testor");
return true;
}else{
System.out.println(" No");
return false;
}
}
public String ifNotTestor(){
int scan = scanBasicMatrix(0);
String x = basicMatrix.get(scan);
int z = x.lastIndexOf("1");
if(s.indexOf("1") > z){
s = s.substring(0,z);
s += "1";
for( int n = z+1; n min= c; n++){
s += "0";
}
return s;
}else{
int index = s.lastIndexOf('1');
scan = scanBasicMatrix(index);
x = basicMatrix.get(scan);
s = s.substring(0,x.lastIndexOf("1"));
s += "1";
for(int n=x.lastIndexOf("1")+1; nmin=c; n++){
s += "0";
}
return s;
}
}
public int scanBasicMatrix(int index){
int maxIndex = -1;
int k = c + 1;
int j = c + 1;
int i = -1;
boolean check = true;
for(String basicMatrixRow: basicMatrix){
check = true;
i++;
for(int m=0; mmin=c; m++){
if(s.charAt(m) == '1' && basicMatrixRow.charAt(m) == '1')
check = false;
}
if(check){
basicMatrixRow = basicMatrixRow.substring(index);
j = basicMatrixRow.lastIndexOf("1");
if(j min k){
k = j;
maxIndex = i;
}
}
}
return maxIndex;
}
}
********* Use Matrix Main
public class UseMatrixMain {
public static void main(String [] args){
UseMatrix useMatrix = new UseMatrix();
useMatrix.setVisible(true);
}
}
Bien ese código :o)
Esto es un algoritmo para controlar procesos vd?
Publicar un comentario